<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>VM Spec  The class File Format</title>
</head>
<body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000>
<table width=100%><tr>
<td><a href="VMSpecTOC.doc.html">Contents</a> | <a href="Overview.doc.html">Prev</a> | <a href="ConstantPool.doc.html">Next</a> | <a href="VMSpecIX.fm.html">Index</a></td><td align=right><i><i>The Java<sup><font size=-2>TM</font></sup> Virtual Machine Specification</i></i></td>
</tr></table>


<hr><br>
 
<a name="80959"></a>
<p><strong>CHAPTER 4 </strong></p>
<a name="80961"></a>
<h1>The <code><font size=+4>class</font></code> File Format</h1>
<hr><p>
<a name="80963"></a>
This chapter describes the Java virtual machine <strong></strong><code>class</code> file format. Each <code>class</code> 
file contains the definition of a single class or interface. Although a class or interface 
need not have an external representation literally contained in a file (for instance, 
because the class is generated by a class loader), we will colloquially refer to any 
valid representation of a class or interface as being in the <code>class</code> file format.
<p><a name="14580"></a>
A <code>class</code> file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first. In the Java and Java 2 platforms, this format is supported by interfaces <code>java.io.DataInput</code> and <code>java.io.DataOutput</code> and classes such as <code>java.io.DataInputStream</code> and <code>java.io.DataOutputStream</code>.<p>
<a name="6289"></a>
This chapter defines its own set of data types representing <code>class</code> file data: The types <code>u1</code>, <code>u2</code>, and <code>u4</code> represent an unsigned one-, two-, or four-byte quantity, respectively. In the Java and Java 2 platforms, these types may be read by methods such as <code>readUnsignedByte</code>, <code>readUnsignedShort</code>, and <code>readInt</code> of the interface <code>java.io.DataInput</code>.<p>
<a name="41600"></a>
This chapter presents the <code>class</code> file format using pseudostructures written in a C-like structure notation. To avoid confusion with the fields of classes and class instances, etc., the contents of the structures describing the <code>class</code> file format are referred to as <em>items</em>. Successive items are stored in the <code>class</code> file sequentially, without padding or alignment. <p>
<a name="74328"></a>
<em>Tables</em>, consisting of zero or more variable-sized items, are used in several <code>class</code> file structures. Although we use C-like array syntax to refer to table items, the fact that tables are streams of varying-sized structures means that it is not possible to translate a table index directly to a byte offset into the table. <p>
<a name="74331"></a>
Where we refer to a data structure as an array, it consists of zero or more contiguous fixed-sized items and can be indexed like an array.<p>
<a name="74353"></a>
<hr><h2>4.1    The <code>ClassFile</code>&#32;Structure</h2>
<a name="44115"></a>
A <code>class</code> file consists of a single <code>ClassFile</code> structure:
<p><pre><br><a name="19050"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>ClassFile {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 magic;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 minor_version;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 major_version;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 constant_pool_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	cp_info constant_pool[constant_pool_count-1];
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 access_flags;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 this_class;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 super_class;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 interfaces_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 interfaces[interfaces_count];
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 fields_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	field_info fields[fields_count];
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 methods_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	method_info methods[methods_count];
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attributes_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	attribute_info attributes[attributes_count];
</code><a name="19084"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="7456"></a>
The items in the <code>ClassFile</code> structure are as follows:
<p><a name="19719"></a>
<dl><dt><code>magic</code><a name="21106"></a>
<dd> The <code>magic</code> item supplies the magic number identifying the <code>class</code> file format; it has the value <code>0xCAFEBABE</code>.<p>
<a name="13448"></a>
<dt><code>minor_version</code>, <code>major_version</code><a name="70425"></a>
<dd> The values of the <code>minor_version</code> and <code>major_version</code> items are the minor and major version numbers of this <code>class</code> file.Together, a major and a minor version number determine the version of the <code>class</code> file format. If a <code>class</code> file has major version number M and minor version number m, we denote the version of its <code>class</code> file format as M.m. Thus, <code>class</code> file format versions may be ordered lexicographically, for example, 1.5 < 2.0 < 2.1.<p>

A Java virtual machine implementation can support a <code>class</code> file format of version v if and only if v lies in some contiguous range Mi.0 <img src="chars/lt_equal.gif"> v <img src="chars/lt_equal.gif"> Mj.m. Only Sun can specify what range of versions a Java virtual machine implementation conforming to a certain release level of the Java platform may support.<a href="#75883"><sup>1</sup></a><p>
<a name="13480"></a>
<dt><code>constant_pool_count</code><a name="31689"></a>
<dd> The value of the <code>constant_pool_count</code> item is equal to the number of entries in the <code>constant_pool</code> table plus one. A <code>constant_pool</code> index is considered valid if it is greater than zero and less than <code>constant_pool_count</code>, with the exception for constants of type <code>long</code> and <code>double</code> noted in <a href="ClassFile.doc.html#1348">&#167;4.4.5</a>.<p>
<a name="29202"></a>
<dt><code>constant_pool[]</code><a name="19096"></a>
<dd> The <code>constant_pool</code> is a table of structures <a href="ClassFile.doc.html#20080">(&#167;4.4)</a> representing various string constants, class and interface names, field names, and other constants that are referred to within the <code>ClassFile</code> structure and its substructures. The format of each <code>constant_pool</code> table entry is indicated by its first "tag" byte.<p>

The <code>constant_pool</code> table is indexed from <code>1</code> to <code>constant_pool_count</code>-<code>1</code>. <p>
<a name="13484"></a>
<dt><code>access_flags</code><a name="23242"></a>
<dd> The value of the <code>access_flags</code> item is a mask of flags used to denote access permissions to and properties of this class or interface. The interpretation of each flag, when set, is as shown in <a href="ClassFile.doc.html#75734">Table 4.1</a>.
</dl>
<a name="75734"></a><p><Table Border="1">
<tr><td><a name="75687"></a>
<strong>Flag Name</strong>
<td><a name="75689"></a>
<strong>Value</strong>
<td><a name="75691"></a>
<strong>Interpretation</strong>

<tr><td><a name="75695"></a>
<code>ACC_PUBLIC</code>
<td><a name="75697"></a>
<code>0x0001</code>
<td><a name="75699"></a>
Declared <code>public</code>; may be accessed from outside its package. 

<tr><td><a name="75703"></a>
<code>ACC_FINAL</code>
<td><a name="75705"></a>
<code>0x0010</code>
<td><a name="75707"></a>
Declared <code>final</code>; no subclasses allowed.

<tr><td><a name="75711"></a>
<code>ACC_SUPER</code>
<td><a name="75713"></a>
<code>0x0020</code>
<td><a name="75715"></a>
Treat superclass methods specially when invoked by the <i>invokespecial</i> instruction.

<tr><td><a name="75719"></a>
<code>ACC_INTERFACE</code>
<td><a name="75721"></a>
<code>0x0200</code>
<td><a name="75723"></a>
Is an interface, not a class.

<tr><td><a name="75727"></a>
<code>ACC_ABSTRACT</code>
<td><a name="75729"></a>
<code>0x0400</code>
<td><a name="75731"></a>
Declared <code>abstract</code>; may not be instantiated.

</Table><br><br><p>
<a name="23301"></a>
An interface is distinguished by its <code>ACC_INTERFACE</code> flag being set. If its <code>ACC_INTERFACE</code> flag is not set, this <code>class</code> file defines a class, not an interface.<p>
<a name="75587"></a>
If the <code>ACC_INTERFACE</code> flag of this <code>class</code> file is set, its <code>ACC_ABSTRACT</code> flag must also be set <a href="Concepts.doc.html#18339">(&#167;2.13.1)</a> and its <code>ACC_PUBLIC</code> flag may be set. Such a <code>class</code> file may not have any of the other flags in <a href="ClassFile.doc.html#75734">Table 4.1</a> set.<p>
<a name="74404"></a>
If the <code>ACC_INTERFACE</code> flag of this <code>class</code> file is not set, it may have any of the other flags in <a href="ClassFile.doc.html#75734">Table 4.1</a> set. However, such a <code>class</code> file cannot have both its <code>ACC_FINAL</code> and <code>ACC_ABSTRACT</code> flags set <a href="Concepts.doc.html#20340">(&#167;2.8.2)</a>. <p>
<a name="75639"></a>
The setting of the <code>ACC_SUPER</code> flag indicates which of two alternative semantics for its <i>invokespecial</i> instruction the Java virtual machine is to express; the <code>ACC_SUPER</code> flag exists for backward compatibility for code compiled by Sun's older compilers for the Java programming language. All new implementations of the Java virtual machine should implement the semantics for <i>invokespecial</i> documented in this specification. All new compilers to the instruction set of the Java virtual machine should set the <code>ACC_SUPER</code> flag. Sun's older compilers generated <code>ClassFile</code> flags with <code>ACC_SUPER</code> unset. Sun's older Java virtual machine implementations ignore the flag if it is set.<p>
<a name="75646"></a>
All bits of the <code>access_flags</code> item not assigned in <a href="ClassFile.doc.html#75734">Table 4.1</a> are reserved for future use. They should be set to zero in generated <code>class</code> files and should be ignored by Java virtual machine implementations.<p>
<a name="13052"></a>
<dl><dt><code>this_class</code><a name="2115"></a>
<dd> The value of the <code>this_class</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing the class or interface defined by this <code>class</code> file.<p>
<a name="18651"></a>
<dt><code>super_class</code>
<dd> For a class, the value of the <code>super_class</code> item either must be zero or must be a valid index into the <code>constant_pool</code> table. If the value of the <code>super_class</code> item is nonzero, the <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing the direct superclass of the class defined by this <code>class</code> file. Neither the direct superclass nor any of its superclasses may be a <code>final</code> class.<p>

If the value of the <code>super_class</code> item is zero, then this <code>class</code> file must represent the class <code>Object</code>, the only class or interface without a direct superclass.<p>

For an interface, the value of the <code>super_class</code> item must always be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Class_info</code> structure representing the class <code>Object</code>.<p>
<a name="18662"></a>
<dt><code>interfaces_count</code>
<dd> The value of the <code>interfaces_count</code> item gives the number of direct superinterfaces of this class or interface type.<p>
<a name="18665"></a>
<dt><code>interfaces[]</code>
<dd> Each value in the <code>interfaces</code> array must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at each value of <code>interfaces[</code><i>i</i><code>]</code>, where <code>0</code> <img src="chars/lt_equal.gif"> i < <code>interfaces_count</code>, must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing an interface that is a direct superinterface of this class or interface type, in the left-to-right order given in the source for the type.<p>
<a name="6758"></a>
<dt>fields_count</code>
<dd> The value of the <code>fields_count</code> item gives the number of <code>field_info</code> structures in the <code>fields</code> table. The <code>field_info </code><a href="ClassFile.doc.html#2877">(&#167;4.5)</a> structures represent all fields, both class variables and instance variables, declared by this class or interface type.<p>
<a name="19653"></a>
<dt><code>fields[]</code>
<dd> Each value in the <code>fields</code> table must be a <code>field_info</code> <a href="ClassFile.doc.html#2877">(&#167;4.5)</a> structure giving a complete description of a field in this class or interface. The <code>fields</code> table includes only those fields that are declared by this class or interface. It does not include items representing fields that are inherited from superclasses or superinterfaces.<p>
<a name="19656"></a>
<dt><code>methods_count</code>
<dd> The value of the <code>methods_count</code> item gives the number of <code>method_info</code> structures in the <code>methods</code> table. <p>
<a name="19659"></a>
<dt><code>methods[]</code>
<dd> Each value in the <code>methods</code> table must be a <code>method_info</code> <a href="ClassFile.doc.html#1513">(&#167;4.6)</a> structure giving a complete description of a method in this class or interface. If the method is not <code>native</code> or <code>abstract</code>, the Java virtual machine instructions implementing the method are also supplied. <p>

The <code>method_info</code> structures represent all methods declared by this class or interface type, including instance methods, class (<code>static</code>) methods, instance initialization methods <a href="Overview.doc.html#12174">(&#167;3.9)</a>, and any class or interface initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>. The <code>methods</code> table does not include items representing methods that are inherited from superclasses or superinterfaces.<p>
<a name="7193"></a>
<dt><code>attributes_count</code>
<dd> The value of the <code>attributes_count</code> item gives the number of attributes <a href="ClassFile.doc.html#43817">(&#167;4.7)</a> in the <code>attributes</code> table of this class.<p>
<a name="19684"></a>
<dt><code>attributes[]</code>
<dd> Each value of the <code>attributes</code> table must be an attribute structure <a href="ClassFile.doc.html#43817">(&#167;4.7)</a>.<p>

The only attributes defined by this specification as appearing in the <code>attributes</code> table of a <code>ClassFile</code> structure are the <code>SourceFile</code> attribute <a href="ClassFile.doc.html#79868">(&#167;4.7.7)</a> and the <code>Deprecated</code> <a href="ClassFile.doc.html#78232">(&#167;4.7.10)</a> attribute.<p>

A Java virtual machine implementation is required to silently ignore any or all attributes in the <code>attributes</code> table of a <code>ClassFile</code> structure that it does not recognize. Attributes not defined in this specification are not allowed to affect the semantics of the <code>class</code> file, but only to provide additional descriptive information <a href="ClassFile.doc.html#16733">(&#167;4.7.1)</a>.<p>
<a name="14757"></a>
</dl>
<hr><h2>4.2    The Internal Form of Fully Qualified Class  and Interface Names</h2>
<a name="14894"></a>
Class and interface names that appear in <code>class</code> file structures are always represented
in a fully qualified form <a href="Concepts.doc.html#20207">(&#167;2.7.5)</a>. Such names are always represented as 
<code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structures and thus may be drawn, where not further
constrained, from the entire Unicode character set. Class names and interfaces
are referenced both from those <code>CONSTANT_NameAndType_info</code> <a href="ClassFile.doc.html#1327">(&#167;4.4.6)</a> 
structures that have such names as part of their descriptor <a href="ClassFile.doc.html#1169">(&#167;4.3)</a> and from all 
<code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structures.
<p><a name="14922"></a>
For historical reasons the syntax of fully qualified class and interface names that appear in <code>class</code> file structures differs from the familiar syntax of fully qualified names documented in <a href="Concepts.doc.html#20207">&#167;2.7.5</a>. In this internal form, the ASCII periods (<code>'</code>.<code>'</code>) that normally separate the identifiers that make up the fully qualified name are replaced by ASCII forward slashes (<code>'/'</code>). For example, the normal fully qualified name of class <code>Thread</code> is <code>java.lang.Thread</code>. In the form used in descriptors in the <code>class</code> file format, a reference to the name of class <code>Thread</code> is implemented using a <code>CONSTANT_Utf8_info</code> structure representing the string <code>"java/lang/Thread"</code>.<p>
<a name="1169"></a>
<hr><h2>4.3    Descriptors</h2>
<a name="1170"></a>
A <em>descriptor</em> is a string representing the type of a field or method. Descriptors are 
represented in the <code>class</code> file format using UTF-8 strings <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> and thus may be 
drawn, where not further constrained, from the entire Unicode character set.
<p><a name="13972"></a>
<h3>4.3.1    Grammar Notation</h3>
<a name="14150"></a>
Descriptors are specified using a grammar. This grammar is a set of productions that 
describe how sequences of characters can form syntactically correct descriptors of 
various types. Terminal symbols of the grammar are shown in bold fixed-width 
font. Nonterminal symbols are shown in <i>italic</i> type. The definition of a nonterminal 
is introduced by the name of the nonterminal being defined, followed by a colon. 
One or more alternative right-hand sides for the nonterminal then follow on succeeding
lines. For example, the production:
<p><a name="81070"></a>
<i>FieldType:</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	<i>BaseType</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	<i>ObjectType</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	<i>ArrayType</i>	<br>
<a name="81068"></a>
<p>
states that a <i>FieldType</i> may represent either a <i>BaseType</i>, an <i>ObjectType</i>, or an <i>ArrayType</i>.
<p><a name="81084"></a>
A nonterminal symbol on the right-hand side of a production that is followed by an asterisk (*) represents zero or more possibly different values produced from that nonterminal, appended without any intervening space. The production:<p>
<a name="81087"></a>
<i>MethodDescriptor:</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;	( <i>ParameterDescriptor* &#32; &#32;</i>) <i>ReturnDescriptor</i><p>
<a name="81085"></a>
states that a <i>MethodDescriptor</i> represents a left parenthesis, followed by zero or 
more <i>ParameterDescriptor</i> values, followed by a right parenthesis, followed by a 
<i>ReturnDescriptor</i>.
<p><a name="14152"></a>
<h3>4.3.2    Field Descriptors</h3>
<a name="7028"></a>
A <i>field descriptor</i> represents the type of a class, instance, or local variable. It is a 
series of characters generated by the grammar:
<p><a name="13975"></a>
&nbsp; &nbsp; &nbsp; &nbsp;<i>FieldDescriptor:</i><br><blockquote><a name="23539"></a>
<i>FieldType</i><p>
</blockquote><a name="23540"></a>
<p>
<a name="23546"></a>
&nbsp; &nbsp; &nbsp; &nbsp;<i>ComponentType:</i><br><blockquote><a name="13979"></a>
<i>FieldType</i><p>
</blockquote><a name="23520"></a>
<p>
<a name="23545"></a>
&nbsp; &nbsp; &nbsp; &nbsp;<i>FieldType:</i><br><blockquote><a name="13982"></a>
<i>BaseType</i><p>
<a name="14135"></a>
<i>ObjectType</i><p>
<a name="13983"></a>
<i>ArrayType</i>        <p>
</blockquote><a name="13984"></a>
<p>
<a name="23547"></a>
&nbsp; &nbsp; &nbsp; &nbsp;<i>BaseType:</i><br><blockquote><a name="13985"></a>
B<p>
<a name="13986"></a>
C<p>
<a name="13987"></a>
D<p>
<a name="13988"></a>
F<p>
<a name="13989"></a>
I<p>
<a name="13990"></a>
J<p>
<a name="13991"></a>
S<p>
<a name="13992"></a>
Z<p>
<a name="14125"></a>
<p>
</blockquote><a name="23548"></a>
&nbsp; &nbsp; &nbsp; &nbsp;<i>ObjectType:</i><br><blockquote><a name="14126"></a>
L &lt;classname&gt; ;<p>
</blockquote><a name="14127"></a>
&nbsp; &nbsp; &nbsp; &nbsp;<i>ArrayType:</i><br><blockquote><a name="14128"></a>
[ <i>ComponentType</i><p>
</blockquote><a name="14019"></a>

<a name="14019"></a>
The characters of <i>BaseType</i>, the L and ; of <i>ObjectType</i>, and the [ of <i>ArrayType</i> are all ASCII characters. The &lt;classname&gt; represents a fully qualified class or interface name. For historical reasons it is encoded in internal form (<a href="ClassFile.doc.html#14757">&#167;4.2)</a>.<p>
<a name="16252"></a>
The interpretation of the field types is as shown in <a href="ClassFile.doc.html#84645">Table 4.2</a>.<p><Table Border="1">
<tr><td><a name="84645"></a>
<i>BaseType</i><strong> Character</strong>
<td><a name="84647"></a>
<strong>Type</strong>
<td><a name="84649"></a>
<strong>Interpretation</strong>

<tr><td><a name="84652"></a>
B
<td><a name="84654"></a>
<code>byte</code>
<td><a name="84656"></a>
signed byte

<tr><td><a name="84659"></a>
C
<td><a name="84661"></a>
<code>char</code>
<td><a name="84663"></a>
Unicode character

<tr><td><a name="84666"></a>
D
<td><a name="84668"></a>
<code>double</code>
<td><a name="84670"></a>
double-precision floating-point value

<tr><td><a name="84673"></a>
F
<td><a name="84675"></a>
<code>float</code>
<td><a name="84677"></a>
single-precision floating-point value

<tr><td><a name="84681"></a>
I
<td><a name="84683"></a>
<code>int</code>
<td><a name="84685"></a>
integer

<tr><td><a name="84689"></a>
J
<td><a name="84691"></a>
<code>long</code>
<td><a name="84693"></a>
long integer

<tr><td><a name="84697"></a>
L&lt;classname&gt;;
<td><a name="84699"></a>
<code>reference</code>
<td><a name="84701"></a>
an instance of class <code>&lt;classname&gt;</code>

<tr><td><a name="84705"></a>
S
<td><a name="84707"></a>
<code>short</code>
<td><a name="84709"></a>
signed short

<tr><td><a name="84713"></a>
Z
<td><a name="84715"></a>
<code>boolean</code>
<td><a name="84717"></a>
<code>true</code> or <code>false</code>

<tr><td><a name="84783"></a>
<strong>[&#32;</strong>
<td><a name="84785"></a>
<code>reference</code>
<td><a name="84787"></a>
one array dimension

</Table><br><br><p>
<a name="84641"></a>
<p>
<a name="84868"></a>
For example, the descriptor of an instance variable of type <code>int</code> is simply I. The descriptor of an instance variable of type <code>Object</code> is Ljava/lang/Object;. Note that the internal form of the fully qualified name for class <code>Object</code> is used. The descriptor of an instance variable that is a multidimensional <code>double</code> array,<p>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>double d[][][];
</code></pre><a name="12776"></a>
is
<p><pre>&nbsp;&nbsp;&nbsp;&nbsp;<strong>[[[D
</strong></pre><a name="7035"></a>
<h3>4.3.3    Method Descriptors</h3>
<a name="74607"></a>
A <i>method descriptor</i> represents the parameters that the method takes and the value 
that it returns:
<p><a name="81101"></a>
<blockquote>
<i>MethodDescriptor:</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;	( <i>ParameterDescriptor* &#32; &#32;</i>) <i>ReturnDescriptor</i><p>
<a name="81108"></a>
</blockquote>
A <i>parameter descriptor </i>represents a parameter passed to a method:<p>
<blockquote>
<a name="14034"></a>
<i>ParameterDescriptor:</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;	<i>FieldType</i><p>
<a name="42504"></a>
</blockquote>
A <i>return descriptor </i>represents the type of the value returned from a method. It is a series of characters generated by the grammar:<p>
<a name="14049"></a>
<blockquote>
<i>ReturnDescriptor:</i><br>
&nbsp;&nbsp;&nbsp;&nbsp;	<i>FieldType</i><br>
	&nbsp;&nbsp;&nbsp;&nbsp;V<p>
	</blockquote>
<a name="7587"></a>
The character V indicates that the method returns no value (its return type is <code>void</code>).<p>
<a name="11151"></a>
A method descriptor is valid only if it represents method parameters with a total length of 255 or less, where that length includes the contribution for <code>this</code> in the case of instance or interface method invocations. The total length is calculated by summing the contributions of the individual parameters, where a parameter of type <code>long</code> or <code>double</code> contributes two units to the length and a parameter of any other type contributes one unit.<p>
<a name="12746"></a>
For example, the method descriptor for the method<p>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>Object mymethod(int i, double d, Thread t)
</code></pre><a name="12751"></a>
is
<p><pre>&nbsp;&nbsp;&nbsp;&nbsp;<strong>(IDLjava/lang/Thread;)Ljava/lang/Object;
</strong></pre><a name="18238"></a>
Note that internal forms of the fully qualified names of <code>Thread</code> and <code>Object</code> are 
used in the method descriptor.
<p><a name="15525"></a>
The method descriptor for <code>mymethod</code> is the same whether <code>mymethod</code> is a class or an instance method. Although an instance method is passed <code>this</code>, a reference to the current class instance, in addition to its intended parameters, that fact is not reflected in the method descriptor. (A reference to <code>this</code> is not passed to a class method.) The reference to <code>this</code> is passed implicitly by the method invocation instructions of the Java virtual machine used to invoke instance methods.<p>
<a name="20080"></a>
<hr><h2>4.4    The Constant Pool</h2>
<a name="9597"></a>
Java virtual machine instructions do not rely on the runtime layout of classes, 
interfaces, class instances, or arrays. Instead, instructions refer to symbolic information
in the <code>constant_pool</code> table. 
<p><a name="36992"></a>
All <code>constant_pool</code> table entries have the following general format:<p>
<pre><br><a name="9604"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>cp_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 info[];
</code><a name="9689"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="86988"></a>
Each item in the <code>constant_pool</code> table must begin with a 1-byte tag indicating the 
kind of <code>cp_info</code> entry. The contents of the <code>info</code> array vary with the value of <code>tag</code>. 
The valid tags and their values are listed in <a href="ClassFile.doc.html#87125">Table 4.3</a>. Each tag byte must be followed by two or more bytes giving information about the specific constant. The format
of the additional information varies with the tag value.<p><Table Border="1">
<tr><th><b><i>Constant Type
</i></b>
<th><b><i>Value
</i></b>
<tr><td><a name="87125"></a>
<code>CONSTANT_Class</code>
<td><a name="87127"></a>
<code>7</code>

<tr><td><a name="87129"></a>
<code>CONSTANT_Fieldref</code>
<td><a name="87131"></a>
<code>9</code>

<tr><td><a name="87133"></a>
<code>CONSTANT_Methodref</code>
<td><a name="87135"></a>
<code>10</code>

<tr><td><a name="87137"></a>
<code>CONSTANT_InterfaceMethodref</code>
<td><a name="87139"></a>
<code>11</code>

<tr><td><a name="87141"></a>
<code>CONSTANT_String</code>
<td><a name="87143"></a>
<code>8</code>

<tr><td><a name="87145"></a>
<code>CONSTANT_Integer</code>
<td><a name="87147"></a>
<code>3</code>

<tr><td><a name="87149"></a>
<code>CONSTANT_Float</code>
<td><a name="87151"></a>
<code>4</code>

<tr><td><a name="87153"></a>
<code>CONSTANT_Long</code>
<td><a name="87155"></a>
<code>5</code>

<tr><td><a name="87157"></a>
<code>CONSTANT_Double</code>
<td><a name="87159"></a>
<code>6</code>

<tr><td><a name="87161"></a>
<code>CONSTANT_NameAndType</code>
<td><a name="87163"></a>
<code>12</code>

<tr><td><a name="87165"></a>
<code>CONSTANT_Utf8</code>
<td><a name="87167"></a>
<code>1</code>

</Table><br><br>
<p><a name="1221"></a>
<h3>4.4.1    The <code>CONSTANT_Class_info</code> Structure</h3>
<a name="1222"></a>
The <code>CONSTANT_Class_info</code> structure is used to represent a class or an interface:
<p><pre><br><a name="1223"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Class_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 name_index;
</code><a name="1226"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9357"></a>
The items of the <code>CONSTANT_Class_info</code> structure are the following:
<p><a name="1228"></a>
<dl><dt><code>tag</code>
<dd> The <code>tag</code> item has the value <code>CONSTANT_Class</code> (<code>7</code>).<p>
<a name="8829"></a>
<dt><code>name_index</code>
<dd> The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing a valid fully qualified class or interface name <a href="Concepts.doc.html#20389">(&#167;2.8.1)</a> encoded in internal form (<a href="ClassFile.doc.html#14757">&#167;4.2)</a>. <p>
</dl>
<a name="84853"></a>
 <p>
<a name="1232"></a>
Because arrays are objects, the opcodes <i>anewarray</i> and <i>multianewarray</i> can reference array "classes" via <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structures in the <code>constant_pool</code> table. For such array classes, the name of the class is the descriptor of the array type. For example, the class name representing a two-dimensional <code>int</code> array type<p>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>int[][] 
</code></pre><a name="1234"></a>
is 
<p><pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>[[I
</code></pre><a name="1237"></a>
The class name representing the type array of class <code>Thread
</code><p><pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>Thread[] 
</code></pre><a name="1239"></a>
is 
<p><pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>[Ljava/lang/Thread;
</code></pre><a name="42039"></a>
An array type descriptor is valid only if it represents 255 or fewer dimensions.
<p><a name="42041"></a>
<h3>4.4.2    The <code>CONSTANT_Fieldref_info</code>, <code>CONSTANT_Methodref_info</code>, and <code>CONSTANT_InterfaceMethodref_info</code> Structures</h3>
<a name="1253"></a>
Fields, methods, and interface methods are represented by similar structures:
<p><pre><br><a name="1254"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Fieldref_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 class_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 name_and_type_index;
</code><a name="1258"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br><br><a name="1260"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Methodref_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 class_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 name_and_type_index;
</code><a name="1264"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br><br><a name="1266"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_InterfaceMethodref_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 class_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 name_and_type_index;
</code><a name="1270"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9360"></a>
The items of these structures are as follows:
<p><a name="6689"></a>
<dl><dt><code>tag</code>
<dd>The <code>tag</code> item of a <code>CONSTANT_Fieldref_info</code> structure has the value <code>CONSTANT_Fieldref</code> (<code>9</code>). <p>
The <code>tag</code> item of a <code>CONSTANT_Methodref_info</code> structure has the value <code>CONSTANT_Methodref</code> (<code>10</code>).<p>

The <code>tag</code> item of a <code>CONSTANT_InterfaceMethodref_info</code> structure has the value <code>CONSTANT_InterfaceMethodref</code> (<code>11</code>).<p>
<a name="1273"></a>
<dt><code>class_index</code>
<dd> The value of the <code>class_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing the class or interface type that contains the declaration of the field or method.<p>

The <code>class_index</code> item of a <code>CONSTANT_Methodref_info</code> structure must be a class type, not an interface type. The <code>class_index</code> item of a <code>CONSTANT_InterfaceMethodref_info</code> structure must be an interface type. The <code>class_index</code> item of a <code>CONSTANT_Fieldref_info</code> structure may be either a class type or an interface type. <p>
<a name="1276"></a>
<dt><code>name_and_type_index</code>
<dd> The value of the <code>name_and_type_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_NameAndType_info</code> <a href="ClassFile.doc.html#1327">(&#167;4.4.6)</a> structure. This <code>constant_pool</code> entry indicates the name and descriptor of the field or method. In a <code>CONSTANT_Fieldref_info</code> the indicated descriptor must be a field descriptor <a href="ClassFile.doc.html#14152">(&#167;4.3.2)</a>. Otherwise, the indicated descriptor must be a method descriptor <a href="ClassFile.doc.html#7035">(&#167;4.3.3)</a>.<p>

If the name of the method of a <code>CONSTANT_Methodref_info</code> structure begins with a<code>'  &lt;'</code> (<code>'\u003c'</code>), then the name must be the special name <code>&lt;init&gt;</code>, representing an instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>. Such a method must return no value. <p>
</dl>
<a name="29297"></a>
<h3>4.4.3    The <code>CONSTANT_String_info</code> Structure</h3>
<a name="21417"></a>
The <code>CONSTANT_String_info</code> structure is used to represent constant objects of the 
type <code>String</code>:
<p><pre><br><a name="21424"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_String_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 string_index;
</code><a name="21426"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9366"></a>
The items of the <code>CONSTANT_String_info</code> structure are as follows:
<p><a name="21646"></a>
<dl><dt><code>tag</code></b><br><a name="21647"></a>
<dd> The <code>tag</code> item of the <code>CONSTANT_String_info</code> structure has the value <code>CONSTANT_String</code> (<code>8</code>).<p>
<a name="6663"></a>
<dt><code>string_index</code></b><br><a name="6664"></a>
<dd> The value of the <code>string_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the sequence of characters to which the <code>String</code> object is to be initialized.<p>
<a name="21942"></a>
</dl>
<h3>4.4.4    The <code>CONSTANT_Integer_info</code> and <code>CONSTANT_Float_info</code> Structures </h3>
<a name="20768"></a>
The <code>CONSTANT_Integer_info</code> and <code>CONSTANT_Float_info</code> structures represent 
4-byte numeric (<code>int</code> and <code>float</code>) constants:
<p><pre><br><a name="20560"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Integer_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 bytes;
</code><a name="20497"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br><br><a name="20499"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Float_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 bytes;
</code><a name="9373"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9376"></a>
The items of these structures are as follows:
<p><a name="9375"></a>
<dl><dt><code>tag</code>
<dd> The <code>tag</code> item of the <code>CONSTANT_Integer_info</code> structure has the value <code>CONSTANT_Integer</code> (<code>3</code>).<p>

The <code>tag</code> item of the <code>CONSTANT_Float_info</code> structure has the value <code>CONSTANT_Float</code> (<code>4</code>).<p>
<a name="20502"></a>
<dt><code>bytes</code>
<dd> The <code>bytes</code> item of the <code>CONSTANT_Integer_info</code> structure represents the value of the <code>int</code> constant. The bytes of the value are stored in big-endian (high byte first) order.<p>

The <code>bytes</code> item of the <code>CONSTANT_Float_info</code> structure represents the value of the <code>float</code> constant in IEEE 754 floating-point single format <a href="Overview.doc.html#28147">(&#167;3.3.2)</a>. The bytes of the single format representation are stored in big-endian (high byte first) order. <p>

The value represented by the <code>CONSTANT_Float_info</code> structure is determined as follows. The bytes of the value are first converted into an <code>int</code> constant bits. Then:<p>
<ul>
<li>If bits is <code>0x7f800000</code>, the <code>float</code> value will be positive infinity.
<li>If bits is <code>0xff800000</code>, the <code>float</code> value will be negative infinity.
<li>If bits is in the range <code>0x7f800001</code> through <code>0x7fffffff</code> or in the range <code>0xff800001</code> through <code>0xffffffff</code>, the <code>float</code> value will be NaN. 
<li>In all other cases, let <code>s</code>, <code>e</code>, and <code>m</code> be three values that might be computed from <em>bits</em>:
</ul><pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>	int s = ((</code>bits<code> &gt;&gt; 31) == 0) ? 1 : -1;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	int e = ((</code>bits<code> &gt;&gt; 23) &amp; 0xff);
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	int m = (e == 0) ?
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>			(</code>bits<code> &amp; 0x7fffff) &lt;&lt; 1 :
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>			(</code>bits<code> &amp; 0x7fffff) | 0x800000;
</code>
Then the <code>float</code> value equals the result of the mathematical expression <code>s&#183;m&#183;2<sup>e-150</sup></code>.
</ul></pre><a name="1348"></a>
<h3>4.4.5    The <code>CONSTANT_Long_info</code> and <code>CONSTANT_Double_info</code> Structures</h3>
<a name="20772"></a>
The <code>CONSTANT_Long_info</code> and <code>CONSTANT_Double_info</code> represent 8-byte 
numeric (<code>long</code> and <code>double</code>) constants:
<p><pre><br><a name="20787"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Long_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 high_bytes;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 low_bytes;
</code><a name="20790"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br><br><a name="21702"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Double_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 high_bytes;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 low_bytes;
</code><a name="21696"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="16625"></a>
All 8-byte constants take up two entries in the <code>constant_pool</code> table of the <code>class</code> file. If a <code>CONSTANT_Long_info</code> or <code>CONSTANT_Double_info</code> structure is the item in the <code>constant_pool</code> table at index <code>n</code>, then the next usable item in the pool is located at index <code>n</code>+<code>2</code>. The <code>constant_pool</code> index <code>n</code>+<code>1</code> must be valid but is considered unusable.<a href="#16628"><sup>2</sup></a><p>
<a name="63028"></a>
The items of these structures are as follows:<p>
<a name="7309"></a>
<dl><dt><code>tag</code>
<dd> The <code>tag</code> item of the <code>CONSTANT_Long_info</code> structure has the value <code>CONSTANT_Long</code> (<code>5</code>).<p>

The <code>tag</code> item of the <code>CONSTANT_Double_info</code> structure has the value <code>CONSTANT_Double</code> (<code>6</code>).<p>
<a name="20793"></a>
<dt><code>high_bytes</code>, <code>low_bytes</code>
<dd> The unsigned <code>high_bytes</code> and <code>low_bytes</code> items of the <code>CONSTANT_Long_info</code> structure together represent the value of the <code>long</code> constant ((<code>long</code>) <code>high_bytes</code> << 32) + <code>low_bytes</code>, where the bytes of each of <code>high_bytes</code> and <code>low_bytes</code> are stored in big-endian (high byte first) order.<p>

The <code>high_bytes</code> and <code>low_bytes</code> items of the <code>CONSTANT_Double_info</code> structure together represent the <code>double</code> value in IEEE 754 floating-point double format <a href="Overview.doc.html#28147">(&#167;3.3.2)</a>. The bytes of each item are stored in big-endian (high byte first) order.<p>

The value represented by the <code>CONSTANT_Double_info</code> structure is determined as follows. The <code>high_bytes</code> and <code>low_bytes</code> items are first converted into the <code>long</code> constant bits, which is equal to ((<code>long</code>) <code>high_bytes</code> << 32) + <code>low_bytes</code>. Then:<p>
<ul>
<li>If bits is <code>0x7ff0000000000000L</code>, the <code>double</code> value will be  positive infinity.
<li>If bits is <code>0xfff0000000000000L</code>, the <code>double</code> value will be  negative infinity.
<li>If bits is in the range <code>0x7ff0000000000001L</code> through <code>0x7fffffffffffffffL</code> or in the range <code>0xfff0000000000001L</code> through <code>0xffffffffffffffffL</code>, the <code>double</code> value will be NaN.
<li>In all other cases, let <code>s</code>, <code>e</code>, and <code>m</code> be three values that might be computed from bits:
</ul><pre>&nbsp;&nbsp;&nbsp;&nbsp;<code>	int s = ((</code>bits<code> &gt;&gt; 63) == 0) ? 1 : -1;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	int e = (int)((</code>bits<code> &gt;&gt; 52) &amp; 0x7ffL);
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	long m = (e == 0) ?
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>		(</code>bits<code> &amp; 0xfffffffffffffL) &lt;&lt; 1 :
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>		(</code>bits<code> &amp; 0xfffffffffffffL) | 0x10000000000000L;
</code></code><ul>
Then the floating-point value equals the <code>double</code> value of the mathematical expression <code>s&#183;m&#183;2<sup>e-1075</sup>.
</ul></pre><a name="1327"></a>
</dl>
<h3>4.4.6    The <code>CONSTANT_NameAndType_info</code> Structure </h3>
<a name="5970"></a>
The <code>CONSTANT_NameAndType_info</code> structure is used to represent a field or 
method, without indicating which class or interface type it belongs to:
<p><pre><br><a name="1328"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_NameAndType_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 descriptor_index;
</code><a name="1332"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9390"></a>
The items of the <code>CONSTANT_NameAndType_info</code> structure are as follows:
<p><a name="1334"></a>
<dl><dt><code>tag</code>
<dd> The <code>tag</code> item of the <code>CONSTANT_NameAndType_info</code> structure has the value <code>CONSTANT_NameAndType</code> (<code>12</code>).<p>
<a name="1336"></a>
<dt><code>name_index</code>
<dd> The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing either a valid field or method name <a href="Concepts.doc.html#21272">(&#167;2.7)</a> stored as a simple name <a href="Concepts.doc.html#21410">(&#167;2.7.1)</a>, that is, as a Java programming language identifier <a href="Concepts.doc.html#25339">(&#167;2.2)</a> or as the special method name <code>&lt;init&gt;</code> <a href="Overview.doc.html#12174">(&#167;3.9)</a>.<p>
<a name="1338"></a>
<dt><code>descriptor_index</code>
<dd> The value of the <code>descriptor_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing a valid field descriptor <a href="ClassFile.doc.html#14152">(&#167;4.3.2)</a> or method descriptor <a href="ClassFile.doc.html#7035">(&#167;4.3.3)</a>.<p>
<a name="7963"></a>
</dl>
<h3>4.4.7    The <code>CONSTANT_Utf8_info</code> Structure</h3>
<a name="1297"></a>
The <code>CONSTANT_Utf8_info</code> structure is used to represent constant string values.
<p><a name="3310"></a>
UTF-8 strings are encoded so that character sequences that contain only non-null ASCII characters can be represented using only 1 byte per character, but characters of up to 16 bits can be represented. All characters in the range <code>'\u0001'</code> to <code>'\u007F'</code> are represented by a single byte:
<p><Table Border="1">
<tr>
 
<td><a name="17391"></a>
 0
<td><a name="17393"></a>
 bits 6-0
</Table><br><p>

<a name="35791"></a>
The 7 bits of data in the byte give the value of the character represented. The null 
character (<code>'\u0000'</code>) and characters in the range <code>'\u0080'</code> to <code>'\u07FF'</code> are represented
by a pair of bytes x and y:<p>

<Table Border="1">
<a name="28487"></a>
 x: 
<tr><td><a name="28489"></a>
 1
<td><a name="28491"></a>
 1
<td><a name="28493"></a>
 0
<td><a name="28495"></a>
 bits 10-6
</Table><br>

<Table Border="1">
<a name="28497"></a>
 y:
<tr><td><a name="28499"></a>
 1
<td><a name="28501"></a>
 0
<td><a name="28503"></a>
 bits 5-0
</Table><br>

<p><a name="35796"></a>
The bytes represent the character with the value ((x & <code>0x1f</code>) << <code>6</code>) + (y & <code>0x3f</code>).
<p><a name="35797"></a>
Characters in the range <code>'\u0800'</code> to <code>'\uFFFF'</code> are represented by 3 bytes x, y, and z:<p>

<Table Border="1">
<a name="35800"></a>
 x:
<tr><td><a name="35802"></a>
 1
<td><a name="35804"></a>
 1
<td><a name="35806"></a>
 1
<td><a name="35808"></a>
 0
<td><a name="35810"></a>
 bits 15-12
</Table><br>

<Table Border="1">
<a name="35812"></a>
 y:
<tr><td><a name="35814"></a>
 1
<td><a name="35816"></a>
 0
<td><a name="35818"></a>
 bits 11-6
</Table><br>

<Table Border="1">
<a name="35820"></a>
 z:
<tr><td><a name="35822"></a>
 1
<td><a name="35824"></a>
 0
<td><a name="35826"></a>
 bits 5-0
</Table><br><p>

<a name="15576"></a>
The character with the value ((x & <code>0xf</code>) << <code>12</code>) + ((y & <code>0x3f</code>) << <code>6</code>) + (z & <code>0x3f</code>) is 
represented by the bytes.
<p><a name="12887"></a>
The bytes of multibyte characters are stored in the <code>class</code> file in big-endian (high byte first) order.<p>
<a name="6111"></a>
There are two differences between this format and the "standard" UTF-8 format. First, the null byte <code>(byte)0</code> is encoded using the 2-byte format rather than the 1-byte format, so that Java virtual machine UTF-8 strings never have embedded nulls. Second, only the 1-byte, 2-byte, and 3-byte formats are used. The Java virtual machine does not recognize the longer UTF-8 formats.<p>
<a name="14071"></a>
For more information regarding the UTF-8 format, see <i>File System Safe UCS Transformation Format (FSS_UTF)</i>, X/Open Preliminary Specification (X/Open Company Ltd., Document Number: P316). This information also appears in ISO/IEC 10646, Annex P.<p>
<a name="7715"></a>
The <code>CONSTANT_Utf8_info</code> structure is<p>
<pre><br><a name="1298"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>CONSTANT_Utf8_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 tag;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 bytes[length];
</code><a name="9399"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9402"></a>
The items of the <code>CONSTANT_Utf8_info</code> structure are the following:
<p><a name="9401"></a>
<dl><dt><code>tag</code>
<dd> The <code>tag</code> item of the <code>CONSTANT_Utf8_info</code> structure has the value <code>CONSTANT_Utf8</code> (<code>1</code>).<p>
<a name="1312"></a>
<dt><code>length</code>
<dd> The value of the <code>length</code> item gives the number of bytes in the <code>bytes</code> array (not the length of the resulting string). The strings in the <code>CONSTANT_Utf8_info</code> structure are not null-terminated.<p>
<a name="2874"></a>
<dt><code>bytes[]</code>
<dd> The <code>bytes</code> array contains the bytes of the string. No byte may have the value <code>(byte)0</code> or lie in the range <code>(byte)0xf0</code>-<code>(byte)0xff</code>.<p>
<a name="2877"></a>
</dl>
<hr><h2>4.5    Fields</h2>
<a name="1480"></a>
Each field is described by a <code>field_info</code> structure. No two fields in one <code>class</code> file 
may have the same name and descriptor <a href="ClassFile.doc.html#14152">(&#167;4.3.2)</a>. The format of this structure is
<p><pre><br><a name="1481"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>field_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 access_flags;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 descriptor_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attributes_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	attribute_info attributes[attributes_count];
</code><a name="87646"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="87647"></a>
The items of the <code>field_info</code> structure are as follows:
<p><a name="87652"></a>
<dl><dt><code>access_flags</code>&#32;&#32;
<dd> The value of the <code>access_flags</code> item is a mask of flags used to denote access permission to and properties of this field. The interpretation of each flag, when set, is as shown in <a href="ClassFile.doc.html#88358">Table 4.4</a>.<p>
Fields of classes may set any of the flags in <a href="ClassFile.doc.html#88358">Table 4.4</a>. However, a specific field of a class may have at most one of its <code>ACC_PRIVATE</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PUBLIC</code> flags set <a href="Concepts.doc.html#18914">(&#167;2.7.4)</a> and may not have both its <code>ACC_FINAL</code> and <code>ACC_VOLATILE</code> flags set <a href="Concepts.doc.html#29882">(&#167;2.9.1)</a>.    
<dd><p><Table Border="1">
<tr><td><a name="88358"></a>
<strong>Flag Name</strong>
<td><a name="88360"></a>
<strong>Value</strong>
<td><a name="88362"></a>
<strong>Interpretation</strong>

<tr><td><a name="88365"></a>
<code>ACC_PUBLIC</code>
<td><a name="88367"></a>
<code>0x0001</code>
<td><a name="88369"></a>
Declared <code>public</code>; may be accessed from outside its package. 

<tr><td><a name="88373"></a>
<code>ACC_PRIVATE</code>
<td><a name="88375"></a>
<code>0x0002</code>
<td><a name="88377"></a>
Declared <code>private</code>; usable only within the defining class.

<tr><td><a name="88381"></a>
<code>ACC_PROTECTED</code>
<td><a name="88383"></a>
<code>0x0004</code>
<td><a name="88385"></a>
Declared <code>protected</code>; may be accessed within subclasses.

<tr><td><a name="88389"></a>
<code>ACC_STATIC</code>
<td><a name="88391"></a>
<code>0x0008</code>
<td><a name="88393"></a>
Declared <code>static</code>. 

<tr><td><a name="88396"></a>
<code>ACC_FINAL</code>
<td><a name="88398"></a>
<code>0x0010</code>
<td><a name="88400"></a>
Declared <code>final</code>; no further assignment after initialization.

<tr><td><a name="88404"></a>
<code>ACC_VOLATILE</code>
<td><a name="88406"></a>
<code>0x0040</code>
<td><a name="88408"></a>
Declared <code>volatile</code>; cannot be cached. 

<tr><td><a name="88412"></a>
<code>ACC_TRANSIENT</code>
<td><a name="88414"></a>
<code>0x0080</code>
<td><a name="88416"></a>
Declared <code>transient</code>; not written or read by a persistent object manager. 

</Table><br><br><p>
Fields of classes may set any of the flags in <a href="ClassFile.doc.html#88358">Table 4.4</a>. However, a specific field of a class may have at most one of its <code>ACC_PRIVATE</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PUBLIC</code> flags set <a href="Concepts.doc.html#18914">(&#167;2.7.4)</a> and may not have both its <code>ACC_FINAL</code> and <code>ACC_VOLATILE</code> flags set <a href="Concepts.doc.html#29882">(&#167;2.9.1)</a>.<p>

All fields of interfaces must have their <code>ACC_PUBLIC</code>, <code>ACC_STATIC</code>, and <code>ACC_FINAL</code> flags set and may not have any of the other flags in <a href="ClassFile.doc.html#88358">Table 4.4</a> set <a href="Concepts.doc.html#18349">(&#167;2.13.3.1)</a>. <p>

All bits of the <code>access_flags</code> item not assigned in <a href="ClassFile.doc.html#88358">Table 4.4</a> are reserved for future use. They should be set to zero in generated <code>class</code> files and should be ignored by Java virtual machine implementations.<p>
<a name="22218"></a>
<dt><code>name_index</code>
<dd> The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure which must represent a valid field name <a href="Concepts.doc.html#21272">(&#167;2.7)</a> stored as a simple name <a href="Concepts.doc.html#21410">(&#167;2.7.1)</a>, that is, as a Java programming language identifier <a href="Concepts.doc.html#25339">(&#167;2.2)</a>.<p>
<a name="1497"></a>
<dt><code>descriptor_index</code>
<dd> The value of the <code>descriptor_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure that must represent a valid field descriptor <a href="ClassFile.doc.html#14152">(&#167;4.3.2)</a>.<p>
<a name="1499"></a>
<dt><code>attributes_count</code>
<dd> The value of the <code>attributes_count</code> item indicates the number of additional attributes <a href="ClassFile.doc.html#43817">(&#167;4.7)</a> of this field.<p>
<a name="1501"></a>
<dt><code>attributes[]</code>
<dd> Each value of the <code>attributes</code> table must be an attribute structure <a href="ClassFile.doc.html#43817">(&#167;4.7)</a>. A field can have any number of attributes associated with it. <p>
The attributes defined by this specification as appearing in the <code>attributes</code> table of a <code>field_info</code> structure are the <code>ConstantValue</code> <a href="ClassFile.doc.html#1405">(&#167;4.7.2)</a>, <code>Synthetic</code> <a href="ClassFile.doc.html#80128">(&#167;4.7.6)</a>, and <code>Deprecated</code> <a href="ClassFile.doc.html#78232">(&#167;4.7.10)</a> attributes. <p>

A Java virtual machine implementation must recognize and correctly read <code>ConstantValue</code> <a href="ClassFile.doc.html#1405">(&#167;4.7.2)</a> attributes found in the <code>attributes</code> table of a <code>field_info</code> structure. A Java virtual machine implementation is required to silently ignore any or all other attributes in the <code>attributes</code> table that it does not recognize. Attributes not defined in this specification are not allowed to affect the semantics of the <code>class</code> file, but only to provide additional descriptive information <a href="ClassFile.doc.html#16733">(&#167;4.7.1)</a>.<p>
<a name="1513"></a>
</dl>
<hr><h2>4.6    Methods</h2>
<a name="1514"></a>
Each method, including each instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a> and the class or 
interface initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>, is described by a <code>method_info</code> structure. No 
two methods in one <code>class</code> file may have the same name and descriptor <a href="ClassFile.doc.html#7035">(&#167;4.3.3)</a>.
<p><a name="84874"></a>
The structure has the following format:<p>
<pre><br><a name="1515"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>method_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 access_flags;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 descriptor_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attributes_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	attribute_info attributes[attributes_count];
</code><a name="1521"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9412"></a>
The items of the <code>method_info</code> structure are as follows:
<p><a name="1522"></a>
<dl><dt><code>access_flags</code>&#32;
<dd> The value of the <code>access_flags</code> item is a mask of flags used to denote access permission to and properties of this method. The interpretation of each flag, when set, is as shown in <a href="ClassFile.doc.html#75568">Table 4.5</a>.
<a name="75568"></a><p><Table Border="1">
<tr><td><a name="75497"></a>
<strong>Flag Name</strong>
<td><a name="75499"></a>
<strong>Value</strong>
<td><a name="75501"></a>
<strong>Interpretation</strong>

<tr><td><a name="75504"></a>
<code>ACC_PUBLIC</code>
<td><a name="75506"></a>
<code>0x0001</code>
<td><a name="75508"></a>
Declared <code>public</code>; may be accessed from outside its package. 

<tr><td><a name="75511"></a>
<code>ACC_PRIVATE</code>
<td><a name="75513"></a>
<code>0x0002</code>
<td><a name="75515"></a>
Declared <code>private</code>; accessible only within the defining class.

<tr><td><a name="75518"></a>
<code>ACC_PROTECTED</code>
<td><a name="75520"></a>
<code>0x0004</code>
<td><a name="75522"></a>
Declared <code>protected</code>; may be accessed within subclasses.

<tr><td><a name="75525"></a>
<code>ACC_STATIC</code>
<td><a name="75527"></a>
<code>0x0008</code>
<td><a name="75529"></a>
Declared <code>static</code>. 

<tr><td><a name="75533"></a>
<code>ACC_FINAL</code>
<td><a name="75535"></a>
<code>0x0010</code>
<td><a name="75537"></a>
Declared <code>final</code>; may not be overridden.

<tr><td><a name="75541"></a>
<code>ACC_SYNCHRONIZED</code>
<td><a name="75543"></a>
<code>0x0020</code>
<td><a name="75545"></a>
Declared <code>synchronized</code>; invocation is wrapped in a monitor lock.

<tr><td><a name="75549"></a>
<code>ACC_NATIVE</code>
<td><a name="75551"></a>
<code>0x0100</code>
<td><a name="75553"></a>
Declared <code>native</code>; implemented in a language other than Java.

<tr><td><a name="75555"></a>
<code>ACC_ABSTRACT</code>
<td><a name="75557"></a>
<code>0x0400</code>
<td><a name="75559"></a>
Declared <code>abstract</code>; no implementation is provided. 

<tr><td><a name="75561"></a>
<code>ACC_STRICT</code>
<td><a name="75563"></a>
<code>0x0800</code>
<td><a name="75565"></a>
Declared <code>strictfp</code>; floating-point mode is FP-strict

</Table><br><br> <p>
Methods of classes may set any of the flags in <a href="ClassFile.doc.html#75568">Table 4.5</a>. However, a specific method of a class may have at most one of its <code>ACC_PRIVATE</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PUBLIC </code>flags set <a href="Concepts.doc.html#18914">(&#167;2.7.4)</a>. If such a method has its <code>ACC_ABSTRACT</code> flag set it may not have any of its <code>ACC_FINAL</code>, <code>ACC_NATIVE</code>, <code>ACC_PRIVATE</code>, <code>ACC_STATIC</code>, <code>ACC_STRICT</code>, or <code>ACC_SYNCHRONIZED</code> flags set <a href="Concepts.doc.html#20648">(&#167;2.13.3.2)</a>.<p>

All interface methods must have their <code>ACC_ABSTRACT</code> and <code>ACC_PUBLIC</code> flags set and may not have any of the other flags in <a href="ClassFile.doc.html#75568">Table 4.5</a> set <a href="Concepts.doc.html#20648">(&#167;2.13.3.2)</a>.<p>

A specific instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a> may have at most one of its <code>ACC_PRIVATE</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PUBLIC</code> flags set and may also have its <code>ACC_STRICT</code> flag set, but may not have any of the other flags in <a href="ClassFile.doc.html#75568">Table 4.5</a> set.<p>

Class and interface initialization methods <a href="Overview.doc.html#12174">(&#167;3.9)</a> are called implicitly by the Java virtual machine; the value of their <code>access_flags</code> item is ignored except for the settings of the <code>ACC_STRICT </code>flag.<p>

All bits of the <code>access_flags</code> item not assigned in <a href="ClassFile.doc.html#75568">Table 4.5</a> are reserved for future use. They should be set to zero in generated <code>class</code> files and should be ignored by Java virtual machine implementations.<p>
<a name="1529"></a>
<dt><code>name_index</code>
<dd> The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing either one of the special method names <a href="Overview.doc.html#12174">(&#167;3.9)</a>, <code>&lt;init&gt;</code> or <code>&lt;clinit&gt;</code>, or a valid method name in the Java programming language <a href="Concepts.doc.html#21272">(&#167;2.7)</a>, stored as a simple name <a href="Concepts.doc.html#21410">(&#167;2.7.1)</a>.<p>
<a name="1531"></a>
<dt><code>descriptor_index</code>
<dd> The value of the <code>descriptor_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing a valid method descriptor <a href="ClassFile.doc.html#7035">(&#167;4.3.3)</a>.<p>
<a name="1533"></a>
<dt><code>attributes_count</code>
<dd> The value of the <code>attributes_count</code> item indicates the number of additional attributes <a href="ClassFile.doc.html#43817">(&#167;4.7)</a> of this method.<p>
<a name="1535"></a>
<dt><code>attributes[]</code>
<dd> Each value of the <code>attributes</code> table must be an attribute structure <a href="ClassFile.doc.html#43817">(&#167;4.7)</a>. A method can have any number of optional attributes associated with it. <p>

The only attributes defined by this specification as appearing in the <code>attributes</code> table of a <code>method_info</code> structure are the <code>Code</code> <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a>, <code>Exceptions</code> <a href="ClassFile.doc.html#3129">(&#167;4.7.4)</a>, <code>Synthetic</code> <a href="ClassFile.doc.html#80128">(&#167;4.7.6)</a>, and <code>Deprecated</code> <a href="ClassFile.doc.html#78232">(&#167;4.7.10)</a> attributes. <p>

A Java virtual machine implementation must recognize and correctly read <code>Code</code> <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a> and <code>Exceptions</code> <a href="ClassFile.doc.html#3129">(&#167;4.7.4)</a> attributes found in the <code>attributes</code> table of a <code>method_info</code> structure. A Java virtual machine implementation is required to silently ignore any or all other attributes in the <code>attributes</code> table of a <code>method_info</code> structure that it does not recognize. Attributes not defined in this specification are not allowed to affect the semantics of the <code>class</code> file, but only to provide additional descriptive information <a href="ClassFile.doc.html#16733">(&#167;4.7.1)</a>.<p>
</dl>
<a name="43817"></a>
<hr><h2>4.7    Attributes</h2>
<a name="43824"></a>
Attributes are used in the <code>ClassFile</code> <a href="ClassFile.doc.html#74353">(&#167;4.1)</a>, <code>field_info</code> <a href="ClassFile.doc.html#2877">(&#167;4.5)</a>, <code>method_info</code> 
<a href="ClassFile.doc.html#1513">(&#167;4.6)</a>, and <code>Code_attribute</code> <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a> structures of the <code>class</code> file format. All 
attributes have the following general format:
<p><pre><br><a name="1712"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>attribute_info {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 info[attribute_length];
</code><a name="1716"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="42211"></a>
For all attributes, the <code>attribute_name_index</code> must be a valid unsigned 16-bit index into the constant pool of the class. The <code>constant_pool</code> entry at <code>attribute_name_index</code> must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the name of the attribute. The value of the <code>attribute_length</code> item indicates the length of the subsequent information in bytes. The length does not include the initial six bytes that contain the <code>attribute_name_index</code> and <code>attribute_length</code> items.<p>
<a name="14354"></a>
Certain attributes are predefined as part of the <code>class</code> file specification. The predefined attributes are the <code>SourceFile</code> <a href="ClassFile.doc.html#79868">(&#167;4.7.7)</a>, <code>ConstantValue</code> <a href="ClassFile.doc.html#1405">(&#167;4.7.2)</a>, <code>Code</code> <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a>, <code>Exceptions</code> <a href="ClassFile.doc.html#3129">(&#167;4.7.4)</a>, <code>InnerClasses</code> <a href="ClassFile.doc.html#79996">(&#167;4.7.5)</a>, <code>Synthetic</code> <a href="ClassFile.doc.html#80128">(&#167;4.7.6)</a>, <code>LineNumberTable</code> <a href="ClassFile.doc.html#22856">(&#167;4.7.8)</a>, <code>LocalVariableTable</code> <a href="ClassFile.doc.html#5956">(&#167;4.7.9)</a>, and <code>Deprecated</code> <a href="ClassFile.doc.html#78232">(&#167;4.7.10)</a> attributes. Within the context of their use in this specification, that is, in the <code>attributes</code> tables of the <code>class</code> file structures in which they appear, the names of these predefined attributes are reserved. <p>
<a name="14381"></a>
Of the predefined attributes, the <code>Code</code>, <code>ConstantValue</code>, and <code>Exceptions</code> attributes must be recognized and correctly read by a <code>class</code> file reader for correct interpretation of the <code>class</code> file by a Java virtual machine implementation. The <code>InnerClasses</code> and <code>Synthetic</code> attributes must be recognized and correctly read by a <code>class</code> file reader in order to properly implement the Java and Java 2 platform class libraries <a href="Overview.doc.html#15641">(&#167;3.12)</a>. Use of the remaining predefined attributes is optional; a <code>class</code> file reader may use the information they contain, or otherwise must silently ignore those attributes.<p>
<a name="16733"></a>
<h3>4.7.1    Defining and Naming New Attributes</h3>
<a name="14388"></a>
Compilers are permitted to define and emit <code>class</code> files containing new attributes in 
the <code>attributes</code> tables of <code>class</code> file structures. Java virtual machine implementations
are permitted to recognize and use new attributes found in the <code>attributes</code> 
tables of <code>class</code> file structures. However, any attribute not defined as part of this Java 
virtual machine specification must not affect the semantics of class or interface 
types. Java virtual machine implementations are required to silently ignore 
attributes they do not recognize.
<p><a name="14402"></a>
For instance, defining a new attribute to support vendor-specific debugging is permitted. Because Java virtual machine implementations are required to ignore attributes they do not recognize, <code>class</code> files intended for that particular Java virtual machine implementation will be usable by other implementations even if those implementations cannot make use of the additional debugging information that the <code>class</code> files contain. <p>
<a name="18262"></a>
Java virtual machine implementations are specifically prohibited from throwing an exception or otherwise refusing to use <code>class</code> files simply because of the presence of some new attribute. Of course, tools operating on <code>class</code> files may not run correctly if given <code>class</code> files that do not contain all the attributes they require.<p>
<a name="18289"></a>
Two attributes that are intended to be distinct, but that happen to use the same attribute name and are of the same length, will conflict on implementations that recognize either attribute. Attributes defined other than by Sun must have names chosen according to the package naming convention defined by <i>The Java</i><sup><font size=-2>TM</font></sup><i> Language Specification</i>. For instance, a new attribute defined by Netscape might have the name <code>"com.Netscape.new-attribute"</code>.<code><a href="#41454"><sup>3</sup></a></code><p>
<a name="14445"></a>
Sun may define additional attributes in future versions of this <code>class</code> file specification. <p>
<a name="1405"></a>
<h3>4.7.2    The <code>ConstantValue</code> Attribute</h3>
<a name="40130"></a>
The <code>ConstantValue</code> attribute is a fixed-length attribute used in the <code>attributes</code> 
table of the <code>field_info</code> <a href="ClassFile.doc.html#2877">(&#167;4.5)</a> structures. A <code>ConstantValue</code> attribute represents 
the value of a constant field that must be (explicitly or implicitly) <code>static</code>; that is, the 
<code>ACC_STATIC</code> bit (<a href="ClassFile.doc.html#88358">Table 4.4</a>) in the <code>flags</code> item of the <code>field_info</code> structure must be 
set. There can be no more than one <code>ConstantValue</code> attribute in the <code>attributes</code> 
table of a given <code>field_info</code> structure. The constant field represented by the 
<code>field_info</code> structure is assigned the value referenced by its <code>ConstantValue</code> 
attribute as part of the initialization of the class or interface declaring the constant 
field <a href="Concepts.doc.html#19075">(&#167;2.17.4)</a>. This occurs immediately prior to the invocation of the class or interface
initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a> of that class or interface.
<p><a name="36278"></a>
If a <code>field_info</code> structure representing a non-<code>static</code> field has a <code>ConstantValue</code> attribute, then that attribute must silently be ignored. Every Java virtual machine implementation must recognize <code>ConstantValue</code> attributes. <p>
<a name="17795"></a>
The <code>ConstantValue</code> attribute has the following format:<p>
<pre><br><a name="1407"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>ConstantValue_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 constantvalue_index;
</code><a name="1411"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9422"></a>
The items of the <code>ConstantValue_attribute</code> structure are as follows:
<p><a name="1412"></a>
<dl><dt><code>attribute_name_index</code>
<dd> 	The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"ConstantValue"</code>.<p>
<a name="1414"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item of a <code>ConstantValue_attribute</code> structure must be <code>2</code>.<p>
<a name="1416"></a>
<dt><code>constantvalue_index</code>
<dd> The value of the <code>constantvalue_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index gives the constant value represented by this attribute. The <code>constant_pool</code> entry must be of a type appropriate to the field, as shown by <a href="ClassFile.doc.html#36388">Table 4.6</a>.
<a name="36388"></a><p><Table Border="1">
<tr><td><b>Field Type</b>
<td><a name="36365"></a>
<b>Entry Type</b>

<tr><td><code>long</code>
<td><a name="36369"></a>
<code>CONSTANT_Long</code>

<tr><td><code>float</code>
<td><a name="36373"></a>
<code>CONSTANT_Float</code>

<tr><td><code>double</code>
<td><a name="36377"></a>
<code>CONSTANT_Double</code>

<tr><td><code>int</code>, <code>short</code>, <code>char</code>, <code>byte</code>, <code>boolean
</code>
<td><a name="36381"></a>
<code>CONSTANT_Integer</code>

<tr><td><code>String</code>
<td><a name="36385"></a>
<code>CONSTANT_String</code>

</Table><br><br> <p>
</dl>
<a name="1546"></a>
<h3>4.7.3    The <code>Code</code> Attribute</h3>
<a name="36322"></a>
The <code>Code</code> attribute is a variable-length attribute used in the <code>attributes</code> table of 
<code>method_info</code> structures. A <code>Code</code> attribute contains the Java virtual machine 
instructions and auxiliary information for a single method, instance initialization 
method <a href="Overview.doc.html#12174">(&#167;3.9)</a>, or class or interface initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>. Every Java virtual 
machine implementation must recognize <code>Code</code> attributes. If the method is either 
<code>native</code> or <code>abstract</code>, its <code>method_info</code> structure must not have a <code>Code</code> attribute. 
Otherwise, its <code>method_info</code> structure must have exactly one <code>Code</code> attribute. 
<p><a name="36419"></a>
The <code>Code</code> attribute has the following format:<p>
<pre><br><a name="1548"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>Code_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 max_stack;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 max_locals;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 code_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u1 code[code_length];
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 exception_table_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	{ &#32; &#32;	u2 start_pc;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	 &#32; &#32; &#32;	u2 end_pc;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	 &#32; &#32; &#32;	u2 &#32;handler_pc;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	 &#32; &#32; &#32;	u2 &#32;catch_type;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	}	exception_table[exception_table_length];
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attributes_count;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	attribute_info attributes[attributes_count];
</code><a name="1564"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="36348"></a>
The items of the <code>Code_attribute</code> structure are as follows:
<p><a name="1565"></a>
<dl><dt><code>attribute_name_index</code>
<dd> The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"Code"</code>.<p>
<a name="1567"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item indicates the length of the attribute, excluding the initial six bytes.<p>
<a name="1569"></a>
<dt><code>max_stack</code></b>
<dd> The value of the <code>max_stack</code> item gives the maximum depth <a href="Overview.doc.html#28851">(&#167;3.6.2)</a> of the operand stack of this method at any point during execution of the method. <p>
<a name="1571"></a>
<dt><code>max_locals</code>
<dd> The value of the <code>max_locals</code> item gives the number of local variables in the local variable array allocated upon invocation of this method, including the local variables used to pass parameters to the method on its invocation. <p>
The greatest local variable index for a value of type <code>long</code> or <code>double</code> is <code>max_locals</code>-<code>2</code>. The greatest local variable index for a value of any other type is <code>max_locals</code>-<code>1</code>.<p>
<a name="6515"></a>
<dt><code>code_length</code>
<dd> The value of the <code>code_length</code> item gives the number of bytes in the <code>code</code> array for this method. The value of <code>code_length</code> must be greater than zero; the <code>code</code> array must not be empty.<p>
<a name="1575"></a>
<dt><code>code[]</code>
<dd> The <code>code</code> array gives the actual bytes of Java virtual machine code that implement the method. <p>

When the <code>code</code> array is read into memory on a byte-addressable machine, if the first byte of the array is aligned on a 4-byte boundary, the <i>tableswitch</i> and <i>lookupswitch</i> 32-bit offsets will be 4-byte aligned. (Refer to the descriptions of those instructions for more information on the consequences of <code>code</code> array alignment.)<p>

The detailed constraints on the contents of the <code>code</code> array are extensive and are given in a separate section <a href="ClassFile.doc.html#40222">(&#167;4.8)</a>.<p>
<a name="10996"></a>
<dt><code>exception_table_length</code>
<dd> The value of the <code>exception_table_length</code> item gives the number of entries in the <code>exception_table</code> table.<p>
<a name="1579"></a>
<dt><code>exception_table[]</code>
<dd> Each entry in the <code>exception_table</code> array describes one exception handler in the <code>code</code> array. The order of the handlers in the <code>exception_table</code> array is significant. See <a href="Overview.doc.html#15494">Section 3.10</a> for more details.<p>

Each <code>exception_table</code> entry contains the following four items:<p>
<a name="6510"></a>
<dl><dt><code>start_pc</code>, <code>end_pc</code>
<dd> The values of the two items <code>start_pc</code> and <code>end_pc</code> indicate the ranges in the <code>code</code> array at which the exception handler is active. The value of <code>start_pc</code> must be a valid index into the <code>code</code> array of the opcode of an instruction. The value of <code>end_pc</code> either must be a valid index into the <code>code</code> array of the opcode of an instruction or must be equal to <code>code_length</code>, the length of the <code>code</code> array. The value of <code>start_pc</code> must be less than the value of <code>end_pc</code>. <p>

The <code>start_pc</code> is inclusive and <code>end_pc</code> is exclusive; that is, the exception handler must be active while the program counter is within the interval [<code>start_pc,</code> <code>end_pc</code>).<a href="#17078"><sup>4</sup></a><p>
<a name="1583"></a>
<dt><code>handler_pc</code>
<dd> The value of the <code>handler_pc</code> item indicates the start of the exception handler. The value of the item must be a valid index into the <code>code</code> array and must be the index of the opcode of an instruction.<p>
<a name="1585"></a>
<dt><code>catch_type</code>
<dd> If the value of the <code>catch_type</code> item is nonzero, it must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing a class of exceptions that this exception handler is designated to catch. This class must be the class <code>Throwable</code> or one of its subclasses. The exception handler will be called only if the thrown exception is an instance of the given class or one of its subclasses.<p>
If the value of the <code>catch_type</code> item is zero, this exception handler is called for all exceptions. This is used to implement <code>finally</code> (see <a href="Compiling.doc.html#13789">Section 7.13, "Compiling <code>finally</code>"</a>).<p>
<a name="29426"></a>
</dl>
<dt><code>attributes_count</code>
<dd> The value of the <code>attributes_count</code> item indicates the number of attributes of the <code>Code</code> attribute. <p>
<a name="1590"></a>
<dt><code>attributes[]</code>
<dd> Each value of the <code>attributes</code> table must be an attribute structure <a href="ClassFile.doc.html#43817">(&#167;4.7)</a>. A <code>Code</code> attribute can have any number of optional attributes associated with it. <p>

Currently, the <code>LineNumberTable</code> <a href="ClassFile.doc.html#22856">(&#167;4.7.8)</a> and <code>LocalVariableTable</code> <a href="ClassFile.doc.html#5956">(&#167;4.7.9)</a> attributes, both of which contain debugging information, are defined and used with the <code>Code</code> attribute.<p>

A Java virtual machine implementation is permitted to silently ignore any or all attributes in the <code>attributes</code> table of a <code>Code</code> attribute. Attributes not defined in this specification are not allowed to affect the semantics of the <code>class</code> file, but only to provide additional descriptive information <a href="ClassFile.doc.html#16733">(&#167;4.7.1)</a>.<p>
<a name="3129"></a>
</dl>
<h3>4.7.4    The <code>Exceptions</code> Attribute</h3>
<a name="74285"></a>
The <code>Exceptions</code> attribute is a variable-length attribute used in the <code>attributes</code> 
table of a <code>method_info</code> <a href="ClassFile.doc.html#1513">(&#167;4.6)</a> structure. The <code>Exceptions</code> attribute indicates which 
checked exceptions a method may throw. There may be at most one <code>Exceptions</code> 
attribute in each <code>method_info</code> structure. 
<p><a name="74291"></a>
The <code>Exceptions</code> attribute has the following format: <p>
<pre><br><a name="5929"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>Exceptions_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 number_of_exceptions;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 exception_index_table[number_of_exceptions];
</code><a name="3138"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9432"></a>
The items of the <code>Exceptions_attribute</code> structure are as follows:
<p><a name="3139"></a>
<dl><dt><code>attribute_name_index</code>
<dd> The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be <code>	</code>the <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"Exceptions"</code>.<p>
<a name="3141"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item indicates the attribute length, excluding the initial six bytes.<p>
<a name="3143"></a>
<dt><code>number_of_exceptions</code>
<dd> The value of the <code>number_of_exceptions</code> item indicates the number of entries in the <code>exception_index_table</code>.<p>
<a name="3145"></a>
<dt><code>exception_index_table[]</code>
<dd> Each value in the <code>exception_index_table</code> array must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry referenced by each table item must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing a class type that this method is declared to throw.<p>
<a name="22778"></a>
<p>
<a name="84639"></a>
</dl>
A method should throw an exception only if at least one of the following three criteria is met:<p>
<ul><li>The exception is an instance of <code>RuntimeException</code> or one of its subclasses.<p>
<li>The exception is an instance of <code>Error</code> or one of its subclasses.<p>
<li>The exception is an instance of one of the exception classes specified in the <code>exception_index_table</code> just described, or one of their subclasses.
</ul><a name="60335"></a>
These requirements are not enforced in the Java virtual machine; they are enforced only at compile time.<p>
<a name="79996"></a>
<h3>4.7.5    The <code>InnerClasses</code> Attribute</h3>
<a name="80000"></a>
The <code>InnerClasses</code> attribute<a href="#79999"><sup>5</sup></a> is a variable-length attribute in the <code>attributes</code> table 
of the <code>ClassFile</code> <a href="ClassFile.doc.html#74353">(&#167;4.1)</a> structure. If the constant pool of a class or interface refers 
to any class or interface that is not a member of a package, its <code>ClassFile</code> structure 
must have exactly one <code>InnerClasses</code> attribute in its <code>attributes</code> table.
<p><a name="80004"></a>
The <code>InnerClasses</code> attribute has the following format:<p>
<pre><br><a name="80006"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>InnerClasses_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 number_of_classes;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	{ &#32;u2 inner_class_info_index;	 &#32;  &#32;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	  &#32;u2 outer_class_info_index;	 &#32;  &#32;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	  &#32;u2 inner_name_index;	 &#32;  &#32;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	  &#32;u2 inner_class_access_flags;	 &#32;  &#32;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	} classes[number_of_classes];
</code><a name="80015"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="80017"></a>
The items of the <code>InnerClasses_attribute</code> structure are as follows:
<p><a name="80019"></a>
<dl><dt><code>attribute_name_index</code>
<dd> The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"InnerClasses"</code>.<p>
<a name="80026"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item indicates the length of the attribute, excluding the initial six bytes.<p>
<a name="80028"></a>
<dt><code>number_of_classes</code>
<dd> The value of the <code>number_of_classes</code> item indicates the number of entries in the <code>classes</code> array.<p>
<a name="80031"></a>
<dt><code>classes[]</code>
<dd> Every <code>CONSTANT_Class_info</code> entry in the <code>constant_pool</code> table which represents a class or interface C that is not a package member must have exactly one corresponding entry in the <code>classes</code> array. <p>

If a class has members that are classes or interfaces, its <code>constant_pool</code> table (and hence its <code>InnerClasses</code> attribute) must refer to each such member, even if that member is not otherwise mentioned by the class. These rules imply that a nested class or interface member will have <code>InnerClasses</code> information for each enclosing class and for each immediate member.<p>
Each <code>classes</code> array entry contains the following four items:<p>
<a name="80035"></a>
<dt><code>inner_class_info_index</code>
<dd> The value of the <code>inner_class_info_index</code> item must be zero or a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing C. The remaining items in the <code>classes</code> array entry give information about C.<p>
<a name="80042"></a>
<dt><code>outer_class_info_index</code>
<dd> If C is not a member, the value of the <code>outer_class_info_index</code> item must be zero. Otherwise, the value of the <code>outer_class_info_index</code> item must be a valid index into the <code>constant_pool</code> table, and the entry at that index must be a <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(&#167;4.4.1)</a> structure representing the class or interface of which C is a member.<p>
<a name="80047"></a>
<dt><code>inner_name_index</code>
<dd> If C is anonymous, the value of the <code>inner_name_index</code> item must be zero. Otherwise, the value of the <code>inner_name_index</code> item must be a valid index into the <code>constant_pool</code> table, and the entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure that represents the original simple name of C, as given in the source code from which this <code>class</code> file was compiled.<p>
<a name="80053"></a>
<dt><code>inner_class_access_flags</code>
<dd> The value of the <code>inner_class_access_flags</code> item is a mask of flags used to denote access permissions to and properties of class or interface C as declared in the source code from which this <code>class</code> file was compiled. It is used by compilers to recover the original information when source code is not available. The flags are shown in <a href="ClassFile.doc.html#88478">Table 4.7</a>.
<a name="88478"></a><p><Table Border="1">
<tr><td><a name="88484"></a>
<strong>Flag Name</strong>
<td><a name="88486"></a>
<strong>Value</strong>
<td><a name="88488"></a>
<strong>Meaning</strong>

<tr><td><a name="88491"></a>
<code>ACC_PUBLIC</code>
<td><a name="88493"></a>
<code>0x0001</code>
<td><a name="88495"></a>
Marked or implicitly <code>public</code> in source. 

<tr><td><a name="88498"></a>
<code>ACC_PRIVATE</code>
<td><a name="88500"></a>
<code>0x0002</code>
<td><a name="88502"></a>
Marked <code>private</code> in source.

<tr><td><a name="88505"></a>
<code>ACC_PROTECTED</code>
<td><a name="88507"></a>
<code>0x0004</code>
<td><a name="88509"></a>
Marked <code>protected</code> in source.

<tr><td><a name="88512"></a>
<code>ACC_STATIC</code>
<td><a name="88514"></a>
<code>0x0008</code>
<td><a name="88516"></a>
Marked or implicitly <code>static</code> in source.

<tr><td><a name="88519"></a>
<code>ACC_FINAL</code>
<td><a name="88521"></a>
<code>0x0010</code>
<td><a name="88523"></a>
Marked <code>final</code> in source.

<tr><td><a name="88526"></a>
<code>ACC_INTERFACE</code>
<td><a name="88528"></a>
<code>0x0200</code>
<td><a name="88530"></a>
Was an <code>interface</code> in source. 

<tr><td><a name="88533"></a>
<code>ACC_ABSTRACT</code>
<td><a name="88535"></a>
<code>0x0400</code>
<td><a name="88537"></a>
Marked or implicitly <code>abstract</code> in source.

</Table><br><br><p>
<a name="88546"></a>
 <p>
All bits of the <code>inner_class_access_flags</code> item not assigned in <a href="ClassFile.doc.html#88478">Table 4.7</a> are reserved for future use. They should be set to zero in generated <code>class</code> files and should be ignored by Java virtual machine implementations.<p>
</dl>
<a name="80126"></a>
The Java virtual machine does not currently check the consistency of the <code>InnerClasses</code> attribute with any <code>class</code> file actually representing a class or interface referenced by the attribute.<p>
<a name="80128"></a>
<h3>4.7.6    The <code>Synthetic</code> Attribute</h3>
<a name="88571"></a>
The <code>Synthetic</code> attribute<a href="#88570"><sup>6</sup></a> is a fixed-length attribute in the <code>attributes</code> table of 
<code>ClassFile</code> <a href="ClassFile.doc.html#74353">(&#167;4.1)</a>, <code>field_info</code> <a href="ClassFile.doc.html#2877">(&#167;4.5)</a>, and <code>method_info</code> <a href="ClassFile.doc.html#1513">(&#167;4.6)</a> structures. A 
class member that does not appear in the source code must be marked using a <code>Synthetic
</code> attribute. 
<p><a name="88547"></a>
<p>
<a name="80144"></a>
The <code>Synthetic</code> attribute has the following format:<p>
<pre><br><a name="80145"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>Synthetic_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code><a name="80148"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="80149"></a>
The items of the <code>Synthetic_attribute</code> structure are as follows:
<p><a name="80151"></a>
<dl><dt><code>attribute_name_index</code>
<dd> The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"Synthetic"</code>.<p>
<a name="80158"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item is zero.<p>
</dl>
<a name="79868"></a>
<h3>4.7.7    The <code>SourceFile</code> Attribute</h3>
<a name="79869"></a>
The <code>SourceFile</code> attribute is an optional fixed-length attribute in the <code>attributes</code> 
table of the <code>ClassFile</code> <a href="ClassFile.doc.html#74353">(&#167;4.1)</a> structure. There can be no more than one 
<code>SourceFile</code> &#32;attribute in the <code>attributes</code> table of a given <code>ClassFile</code> structure. 
<p><a name="79874"></a>
The <code>SourceFile</code> attribute has the following format:<p>
<pre><br><a name="79875"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>SourceFile_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 sourcefile_index;
</code><a name="79879"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="79880"></a>
The items of the <code>SourceFile_attribute</code> structure are as follows:
<p><a name="79882"></a>
<dl><dt><code>attribute_name_index</code>
<dd> The 	 value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"SourceFile"</code>.<p>
<a name="79889"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item of a <code>SourceFile_attribute</code> structure must be <code>2</code>.<p>
<a name="79891"></a>
<dt><code>sourcefile_index</code>
<dd> The value of the <code>sourcefile_index</code> item must be a valid index into the <code>constant_pool</code> table. The constant pool entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing a string. <p>

The string referenced by the <code>sourcefile_index</code> item will be interpreted as indicating the name of the source file from which this <code>class</code> file was compiled. It will not be interpreted as indicating the name of a directory containing the file or an absolute path name for the file; such platform-specific additional information must be supplied by the runtime interpreter or development tool at the time the file name is actually used.<p>
</dl>
<a name="22856"></a>
<h3>4.7.8    The <code>LineNumberTable</code> Attribute</h3>
<a name="23308"></a>
The <code>LineNumberTable</code> attribute is an optional variable-length attribute in the 
<code>attributes</code> table of a <code>Code</code> <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a> attribute. It may be used by debuggers to 
determine which part of the Java virtual machine <code>code</code> array corresponds to a given 
line number in the original source file. If <code>LineNumberTable</code> attributes are present 
in the <code>attributes</code> table of a given <code>Code</code> attribute, then they may appear in any 
order. Furthermore, multiple <code>LineNumberTable</code> attributes may together represent a 
given line of a source file; that is, <code>LineNumberTable</code> attributes need not be one-to-one with source lines. 
<p><a name="23315"></a>
The <code>LineNumberTable</code> attribute has the following format:<p>
<pre><br><a name="23316"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>LineNumberTable_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 line_number_table_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	{ &#32;u2 start_pc;	 &#32;  &#32;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	  &#32;u2 line_number;	 &#32;  &#32;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	} line_number_table[line_number_table_length];
</code><a name="1602"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="9437"></a>
The items of the <code>LineNumberTable_attribute</code> structure are as follows:
<p><a name="1603"></a>
<dl><dt><code>attribute_name_index</code>
<dd>The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"LineNumberTable"</code>. <p>
<a name="24012"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item indicates the length of the attribute, excluding the initial six bytes.<p>
<a name="1607"></a>
<dt><code>line_number_table_length</code>
<dd> The value of the <code>line_number_table_length</code> item indicates the number of entries in the <code>line_number_table</code> array.<p>
<a name="1609"></a>
<dt><code>line_number_table[]</code>
<dd> Each entry in the <code>line_number_table</code> array indicates that the line number in the original source file changes at a given point in the <code>code</code> array. Each <code>line_number_table</code> entry must contain the following two items:<p>
<a name="1611"></a>
<dt><code>start_pc</code>
<dd> The value of the <code>start_pc</code> item must indicate the index into the <code>code</code> array at which the code for a new line in the original source file begins. The value of <code>start_pc</code> must be less than the value of the <code>code_length</code> item of the <code>Code</code> attribute of which this <code>LineNumberTable</code> is an attribute.<p>
<a name="5953"></a>
<dt><code>line_number</code>
<dd> The value of the <code>line_number</code> item must give the corresponding line number in the original source file.<p>
</dl>
<a name="5956"></a>
<h3>4.7.9    The <code>LocalVariableTable</code> Attribute</h3>
<a name="5957"></a>
The <code>LocalVariableTable</code> attribute is an optional variable-length attribute of a 
<code>Code</code> <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a> attribute. It may be used by debuggers to determine the value of a 
given local variable during the execution of a method. If <code>LocalVariableTable</code> 
attributes are present in the <code>attributes</code> table of a given <code>Code</code> attribute, then they 
may appear in any order. There may be no more than one <code>LocalVariableTable</code> 
attribute per local variable in the <code>Code</code> attribute.
<p><a name="17799"></a>
The <code>LocalVariableTable</code> attribute has the following format:<p>
<pre><br><a name="1617"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>LocalVariableTable_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 local_variable_table_length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	{ &#32;u2 start_pc;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	 &#32; &#32;u2 length;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	 &#32; &#32;u2 name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	 &#32; &#32;u2 descriptor_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	 &#32; &#32;u2 index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	} local_variable_table[local_variable_table_length];
</code><a name="5938"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}	
</code><br></pre><a name="9442"></a>
The items of the <code>LocalVariableTable_attribute</code> structure are as follows:
<p><a name="1628"></a>
<dl><dt><code>attribute_name_index</code>
<dd> The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"LocalVariableTable"</code>.<p>
<a name="1630"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item indicates the length of the attribute, excluding the initial six bytes.<p>
<a name="1632"></a>
<dt><code>local_variable_table_length</code>
<dd> The value of the <code>local_variable_table_length</code> item indicates the number of entries in the <code>local_variable_table</code> array.<p>
<a name="1634"></a>
<dt><code>local_variable_table[]</code>
<dd> Each entry in the <code>local_variable_table</code> array indicates a range of <code>code</code> array offsets within which a local variable has a value. It also indicates the index into the local variable array of the current frame at which that local variable can be found. Each entry must contain the following five items:<p>
<a name="1636"></a>
<dt><code>start_pc</code>, <code>length</code>
<dd> The given local variable must have a value at indices into the <code>code</code> array in the interval [<code>start_pc</code>, <code>start_pc+length</code>], that is, between <code>start_pc</code> and <code>start_pc+length</code> inclusive. The value of <code>start_pc</code> must be a valid index into the <code>code</code> array of this <code>Code</code> attribute and must be the index of the opcode of an instruction. Either the value of <code>start_pc+length</code> must be a valid index into the <code>code</code> array of this <code>Code</code> attribute and be the index of the opcode of an instruction, or it must be the first index beyond the end of that <code>code</code> array.<p>
<a name="1638"></a>
<dt><code>name_index</code>, <code>descriptor_index</code>
<dd> The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must contain a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a><code> </code>structure representing a valid local variable name stored as a simple name <a href="Concepts.doc.html#21410">(&#167;2.7.1)</a>.<p>
The value of the <code>descriptor_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must contain a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing a field descriptor <a href="ClassFile.doc.html#14152">(&#167;4.3.2)</a> encoding the type of a local variable in the source program. <p>
<a name="1640"></a>
<dt><code>index</code>
<dd> The given local variable must be at <code>index</code> in the local variable array of the current frame. If the local variable at <code>index</code> is of type <code>double</code> or <code>long</code>, it occupies both <code>index</code> and <code>index+1</code>.<p>
</dl>
<a name="78232"></a>
<h3>4.7.10    The <code>Deprecated</code> Attribute</h3>
<a name="78237"></a>
The <code>Deprecated</code> attribute<a href="#78236"><sup>7</sup></a> is an optional fixed-length attribute in the <code>attributes</code> 
table of <code>ClassFile</code> <a href="ClassFile.doc.html#74353">(&#167;4.1)</a>, <code>field_info</code> <a href="ClassFile.doc.html#2877">(&#167;4.5)</a>, and <code>method_info</code> <a href="ClassFile.doc.html#1513">(&#167;4.6)</a> structures.
A class, interface, method, or field may be marked using a <code>Deprecated</code> 
attribute to indicate that the class, interface, method, or field has been superseded. A 
runtime interpreter or tool that reads the <code>class</code> file format, such as a compiler, can 
use this marking to advise the user that a superseded class, interface, method, or 
field is being referred to. The presence of a <code>Deprecated</code> attribute does not alter the 
semantics of a class or interface.
<p><a name="78248"></a>
The <code>Deprecated</code> attribute has the following format:<p>
<pre><br><a name="78249"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>Deprecated_attribute {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u2 attribute_name_index;
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>	u4 attribute_length;
</code><a name="78252"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><br></pre><a name="78253"></a>
The items of the <code>Deprecated_attribute</code> structure are as follows:
<p><a name="78255"></a>
<dl><dt><code>attribute_name_index</code>
<dd> The value of the <code>attribute_name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a> structure representing the string <code>"Deprecated"</code>.<p>
<a name="78262"></a>
<dt><code>attribute_length</code>
<dd> The value of the <code>attribute_length</code> item is zero.<p>
</dl>
<a name="40222"></a>
<hr><h2>4.8    Constraints on Java Virtual Machine Code</h2>
<a name="40226"></a>
The Java virtual machine code for a method, instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>, 
or class or interface initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a> is stored in the <code>code</code> array of the 
<code>Code</code> attribute of a <code>method_info</code> structure of a <code>class</code> file. This section describes 
the constraints associated with the contents of the <code>Code_attribute</code> structure.
<p><a name="9279"></a>
<h3>4.8.1    Static Constraints</h3>
<a name="11830"></a>
The <i>static constraints</i> on a <code>class</code> file are those defining the well-formedness of the 
file. With the exception of the static constraints on the Java virtual machine code of 
the <code>class</code> file, these constraints have been given in the previous section. The static 
constraints on the Java virtual machine code in a <code>class</code> file specify how Java virtual 
machine instructions must be laid out in the <code>code</code> array and what the operands of 
individual instructions must be.
<p><a name="88585"></a>
<p>
<a name="88586"></a>
<p>
<a name="11915"></a>
<p>
<a name="88587"></a>
The static constraints on the instructions in the <code>code</code> array are as follows:<p>
<ul><li>The <code>code</code> array must not be empty, so the <code>code_length</code> item cannot have the value <code>0</code>. <p>
<li>The value of the <code>code_length</code> item must be less than <code>65536</code>. <p>
<li>The opcode of the first instruction in the <code>code</code> array begins at index <code>0</code>. <p>
<li>Only instances of the instructions documented in <a href="Instructions.doc.html#66646">Section 6.4</a> may appear in the <code>code</code> array. Instances of instructions using the reserved opcodes <a href="Instructions.doc.html#60105">(&#167;6.2)</a> or any opcodes not documented in this specification may not appear in the <code>code</code> array. <p>
<li>For each instruction in the <code>code</code> array except the last, the index of the opcode of the next instruction equals the index of the opcode of the current instruction plus the length of that instruction, including all its operands. The <i>wide</i> instruction is treated like any other instruction for these purposes; the opcode specifying the operation that a <i>wide</i> instruction is to modify is treated as one of the operands of that <i>wide</i> instruction. That opcode must never be directly reachable by the computation.<p>
<li>The last byte of the last instruction in the <code>code</code> array must be the byte at index <code>code_length</code>-<code>1</code>.
</ul><a name="42772"></a>
The static constraints on the operands of instructions in the <code>code</code> array are as follows:

<p><ul><li>The target of each jump and branch instruction (<i>jsr</i>, <i>jsr_w</i>, <i>goto</i>, <i>goto_w</i>, <i>ifeq</i>, <i>ifne</i>, <i>ifle</i>, <i>iflt</i>, <i>ifge</i>, <i>ifgt</i>, <i>ifnull</i>, <i>ifnonnull</i>, <i>if_icmpeq</i>, <i>if_icmpne</i>, <i>if_icmple</i>, <i>if_icmplt</i>, <i>if_icmpge</i>, <i>if_icmpgt</i>, <i>if_acmpeq</i>, <i>if_acmpne</i>) must be the opcode of an instruction within this method. The target of a jump or branch instruction must never be the opcode used to specify the operation to be modified by a <i>wide</i> instruction; a jump or branch target may be the <i>wide</i> instruction itself.<p>
<li>Each target, including the default, of each <i>tableswitch</i> instruction must be the opcode of an instruction within this method. Each <i>tableswitch</i> instruction must have a number of entries in its jump table that is consistent with the value of its <i>low</i> and <i>high</i> jump table operands, and its <i>low</i> value must be less than or equal to its <i>high</i> value. No target of a <i>tableswitch</i> instruction may be the opcode used to specify the operation to be modified by a <i>wide</i> instruction; a <i>tableswitch</i>  target may be a <i>wide</i> instruction itself.<p>
<li>Each target, including the default, of each <i>lookupswitch</i> instruction must be the opcode of an instruction within this method. Each <i>lookupswitch</i> instruction must have a number of <i>match-offset</i> pairs that is consistent with the value of its <i>npairs</i> operand. The <i>match-offset</i> pairs must be sorted in increasing numerical order by signed <i>match</i> value. No target of a <i>lookupswitch</i> instruction may be the opcode used to specify the operation to be modified by a <i>wide</i> instruction; a <i>lookupswitch</i> target may be a <i>wide</i> instruction itself.<p>
<li>The operand of each <i>ldc</i> instruction must be a valid index into the <code>constant_pool</code> table. The operands of each <i>ldc_w</i> instruction must represent a valid index into the <code>constant_pool</code> table. In both cases the constant pool entry referenced by that index must be of type <code>CONSTANT_Integer</code>, <code>CONSTANT_Float</code>, or <code>CONSTANT_String</code>. <p>
<li>The operands of each <i>ldc2_w</i> instruction must represent a valid index into the <code>constant_pool</code> table. The constant pool entry referenced by that index must be of type <code>CONSTANT_Long</code> or <code>CONSTANT_Double</code>. In addition, the subsequent constant pool index must also be a valid index into the constant pool, and the constant pool entry at that index must not be used. <p>
<li>The operands of each <i>getfield</i>, <i>putfield</i>, <i>getstatic</i>, and <i>putstatic</i> instruction must represent a valid index into the <code>constant_pool</code> table. The constant pool entry referenced by that index must be of type <code>CONSTANT_Fieldref</code>. <p>
<li>The indexbyte operands of each <i>invokevirtual</i>, <i>invokespecial</i>, and <i>invokestatic</i> instruction must represent a valid index into the <code>constant_pool</code> table. The constant pool entry referenced by that index must be of type <code>CONSTANT_Methodref</code>. <p>
<li>Only the <i>invokespecial</i> instruction is allowed to invoke an instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>. No other method whose name begins with the character <code>'&lt;'</code> (<code>'\u003c'</code>) may be called by the method invocation instructions. In particular, the class or interface initialization method specially named <code>&lt;clinit&gt;</code> is never called explicitly from Java virtual machine instructions, but only implicitly by the Java virtual machine itself.<p>
<li>The indexbyte operands of each <i>invokeinterface</i> instruction must  represent a valid index into the <code>constant_pool</code> table. The constant pool entry referenced by that index must be of type <code>CONSTANT_InterfaceMethodref</code>. The value of the <i>count</i> operand of each <i>invokeinterface</i>  instruction must reflect the number of local variables necessary to store the arguments to be passed to the interface method, as implied by the descriptor of the <code>CONSTANT_NameAndType_info</code> structure referenced by the <code>CONSTANT_InterfaceMethodref</code> constant pool entry. The fourth operand byte of each <i>invokeinterface</i> instruction must have the value zero.<p>
<li>The operands of each <i>instanceof</i>, <i>checkcast</i>, <i>new</i>, and <i>anewarray</i> instruction and the indexbyte operands of each <i>multianewarray</i> instruction must represent a valid index into the <code>constant_pool</code> table. The constant pool entry referenced by that index must be of type <code>CONSTANT_Class</code>.<p>
<li>No <i>anewarray</i> instruction may be used to create an array of more than 255 dimensions.<p>
<li>No <i>new</i> instruction may reference a <code>CONSTANT_Class</code> <code>constant_pool</code> table entry representing an array class. The <i>new</i> instruction cannot be used to create an array. The <i>new</i> instruction also cannot be used to create an instance of an interface or an instance of an <code>abstract</code> class.<p>
<li>A <i>multianewarray</i> instruction must be used only to create an array of a type that has at least as many dimensions as the value of its <i>dimensions</i> operand. That is, while a <i>multianewarray</i> instruction is not required to create all of the dimensions of the array type referenced by its indexbyte operands, it must not attempt to create more dimensions than are in the array type. The <i>dimensions</i> operand of each <i>multianewarray</i> instruction must not be zero.<p>
<li>The <i>atype</i> operand of each <i>newarray</i> instruction must take one of the values <code>T_BOOLEAN</code> (<code>4</code>), <code>T_CHAR</code> (<code>5</code>), <code>T_FLOAT</code> (<code>6</code>), <code>T_DOUBLE</code> (<code>7</code>), <code>T_BYTE</code> (<code>8</code>), <code>T_SHORT</code> (<code>9</code>), <code>T_INT</code> (<code>10</code>), or <code>T_LONG</code> (<code>11</code>).<p>
<li>The index operand of each <i>iload</i>, <i>fload</i>, <i>aload</i>, <i>istore</i>, <i>fstore</i>, <i>astore</i>, <i>iinc</i>, and <i>ret</i> instruction must be a nonnegative integer no greater than <code>max_locals</code>-<code>1</code>. <p>
<li>The implicit index of each <i>iload_&lt;n&gt;</i>, <i>fload_&lt;n&gt;</i>, <i>aload_&lt;n&gt;</i>, <i>istore_&lt;n&gt;</i>, <i>fstore_&lt;n&gt;</i>, and <i>astore_&lt;n&gt;</i> instruction must be no greater than the value of <code>max_locals</code>-<code>1</code>.<p>
<li>The index operand of each <i>lload</i>, <i>dload</i>, <i>lstore</i>, and <i>dstore</i> instruction must be no greater than the value of <code>max_locals</code>-<code>2</code>.<p>
<li>The implicit index of each <i>lload_&lt;n&gt;</i>, <i>dload_&lt;n&gt;</i>, <i>lstore_&lt;n&gt;</i>, and <i>dstore_&lt;n&gt;</i> instruction must be no greater than the value of <code>max_locals</code>-<code>2</code>.<p>
<li>The indexbyte operands of each <i>wide</i> instruction modifying an <i>iload</i>, <i>fload</i>, <i>aload</i>, <i>istore</i>, <i>fstore</i>, <i>astore</i>, <i>ret</i>, or <i>iinc</i> instruction must represent a nonnegative integer no greater than <code>max_locals</code>-<code>1</code>. The indexbyte operands of each <i>wide</i> instruction modifying an <i>lload</i>, <i>dload</i>, <i>lstore</i>, or <i>dstore</i> instruction must represent a nonnegative integer no greater than <code>max_locals</code>-<code>2</code>.
</ul><a name="9308"></a>
<h3>4.8.2    Structural Constraints</h3>
<a name="11914"></a>
The structural constraints on the <code>code</code> array specify constraints on relationships 
between Java virtual machine instructions. The structural constraints are as follows:

<p><ul><li>Each instruction must only be executed with the appropriate type and number of arguments in the operand stack and local variable array, regardless of the execution path that leads to its invocation. An instruction operating on values of type <code>int</code> is also permitted to operate on values of type <code>boolean</code>, <code>byte</code>, <code>char</code>, and <code>short</code>. (As noted in <a href="Overview.doc.html#22909">&#167;3.3.4</a> and <a href="Overview.doc.html#7565">&#167;3.11.1</a>, the Java virtual machine internally converts values of types <code>boolean</code>, <code>byte</code>, <code>char</code>, and <code>short</code> to type <code>int</code>.)<p>
<li>If an instruction can be executed along several different execution paths, the operand stack must have the same depth <a href="Overview.doc.html#28851">(&#167;3.6.2)</a> prior to the execution of the instruction, regardless of the path taken.<p>
<li>At no point during execution can the order of the local variable pair holding a value of type <code>long</code> or <code>double</code> be reversed or the pair split up. At no point can the local variables of such a pair be operated on individually.<p>
<li>No local variable (or local variable pair, in the case of a value of type <code>long</code> or <code>double</code>) can be accessed before it is assigned a value.<p>
<li>At no point during execution can the operand stack grow to a depth <a href="Overview.doc.html#28851">(&#167;3.6.2)</a> greater than that implied by the <code>max_stack</code> item.<p>
<li>At no point during execution can more values be popped from the operand stack than it contains.<p>
<li>Each <i>invokespecial</i> instruction must name an instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>, a method in the current class, or a method in a superclass of the current class. <p>
<li>When the instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a> is invoked, an uninitialized class instance must be in an appropriate position on the operand stack. An instance initialization method must never be invoked on an initialized class instance.<p>
<li>When any instance method is invoked or when any instance variable is accessed, the class instance that contains the instance method or instance  variable must already be initialized.<p>
<li>There must never be an uninitialized class instance on the operand stack or in a local variable when any backwards branch is taken. There must never be an uninitialized class instance in a local variable in code protected by an exception handler. However, an uninitialized class instance may be on the operand stack in code protected by an exception handler. When an exception is thrown, the contents of the operand stack are discarded.<p>
<li>Each instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a>, except for the instance initialization method derived from the constructor of class <code>Object</code>, must call either another instance initialization method of <code>this</code> or an instance initialization method of its direct superclass <code>super</code> before its instance members are accessed. However, instance fields of <code>this</code> that are declared in the current class may be assigned before calling any instance initialization method. <p>
<li>The arguments to each method invocation must be method invocation compatible <a href="Concepts.doc.html#19685">(&#167;2.6.8)</a> with the method descriptor <a href="ClassFile.doc.html#7035">(&#167;4.3.3)</a>.<p>
<li>The type of every class instance that is the target of a method invocation instruction must be assignment compatible <a href="Concepts.doc.html#19674">(&#167;2.6.7)</a> with the class or interface type specified in the instruction.<p>
<li>Each return instruction must match its method's return type. If the method returns a <code>boolean</code>, <code>byte</code>, <code>char</code>, <code>short</code>, or <code>int</code>, only the <i>ireturn</i> instruction may be used. If the method returns a <code>float</code>, <code>long</code>, or <code>double</code>, only an <i>freturn</i>, <i>lreturn</i>, or<i> dreturn </i>instruction, respectively, may be used. If the method returns a <code>reference</code> &#32;type, it must do so using an <i>areturn</i> instruction, and the type of the returned value must be assignment compatible <a href="Concepts.doc.html#19674">(&#167;2.6.7)</a> with the return descriptor <a href="ClassFile.doc.html#7035">(&#167;4.3.3)</a> of the method. All instance initialization methods, class or interface initialization methods, and methods declared to return <code>void</code> must use only the <i>return</i> instruction.<p>
<li>If <i>getfield </i>or<i> putfield</i> is used to access a <code>protected</code> field of a superclass, then the type of the class instance being accessed must be the same as or a subclass of the current class. If <i>invokevirtual</i> or <i>invokespecial </i>is used to access a  <code>protected</code> method of a superclass, then the type of the class instance being accessed must be the same as or a subclass of the current class.<p>
<li>The type of every class instance accessed by a <i>getfield</i> instruction or modified by a <i>putfield</i> &#32;instruction must be assignment compatible <a href="Concepts.doc.html#19674">(&#167;2.6.7)</a> with the class type specified in the instruction.<p>
<li>The type of every value stored by a <i>putfield</i> or <i>putstatic</i> instruction must be compatible with the descriptor of the field <a href="ClassFile.doc.html#14152">(&#167;4.3.2)</a> of the class instance or class being stored into. If the descriptor type is <code>boolean</code>, <code>byte</code>, <code>char</code>, <code>short</code>, or <code>int</code>, then the value must be an <code>int</code>. If the descriptor type is <code>float</code>, <code>long</code>, or <code>double</code>, then the value must be a <code>float</code>, <code>long</code>, or <code>double</code>, respectively. If the descriptor type is a <code>reference</code> type, then the value must be of a type that is assignment compatible <a href="Concepts.doc.html#19674">(&#167;2.6.7)</a> with the descriptor type.<p>
<li>The type of every value stored into an array of type <code>reference</code> by an <i>aastore</i> instruction must be assignment compatible <a href="Concepts.doc.html#19674">(&#167;2.6.7)</a> with the component type of the array.<p>
<li>Each <i>athrow</i> instruction must throw only values that are instances of class <code>Throwable</code> or of subclasses of <code>Throwable</code>.<p>
<li>Execution never falls off the bottom of the <code>code</code> array.<p>
<li>No return address (a value of type <code>returnAddress</code>) may be loaded from a local variable.<p>
<li>The instruction following each <i>jsr</i> or <i>jsr_w</i> instruction may be returned to only by a single <i>ret</i> instruction. <p>
<li>No <i>jsr</i> or <i>jsr_w</i> instruction may be used to recursively call a subroutine if that subroutine is already present in the subroutine call chain. (Subroutines can be nested when using <code>try</code>-<code>finally</code> constructs from within a <code>finally</code> clause. For more information on Java virtual machine subroutines, see <a href="ClassFile.doc.html#9862">&#167;4.9.6</a>.)<p>
<li>Each instance of type <code>returnAddress</code> can be returned to at most once. If a <i>ret</i> instruction returns to a point in the subroutine call chain above the <i>ret</i> instruction corresponding to a given instance of type <code>returnAddress</code>, then that instance can never be used as a return address.
</ul><a name="88597"></a>
<hr><h2>4.9    Verification of <code><font size=+4>class</font></code> Files</h2>
<a name="84608"></a>
Even though Sun's compiler for the Java programming language attempts to produce
only class files that satisfy all the static constraints in the previous sections, the 
Java virtual machine has no guarantee that any file it is asked to load was generated 
by that compiler or is properly formed. Applications such as Sun's HotJava World 
Wide Web browser do not download source code, which they then compile; these 
applications download already-compiled <code>class</code> files. The HotJava browser needs to 
determine whether the <code>class</code> file was produced by a trustworthy compiler or by an 
adversary attempting to exploit the virtual machine. 
<p><a name="17902"></a>
An additional problem with compile-time checking is version skew. A user may have successfully compiled a class, say <code>PurchaseStockOptions</code>, to be a subclass of <code>TradingClass</code>. But the definition of <code>TradingClass</code> might have changed since the time the class was compiled in a way that is not compatible with preexisting binaries. Methods might have been deleted or had their return types or modifiers changed. Fields might have changed types or changed from instance variables to class variables. The access modifiers of a method or variable may have changed from <code>public</code> to <code>private</code>. For a discussion of these issues, see Chapter 13, "Binary Compatibility," in the first edition of <i>The</i> <i>Java</i><sup><font size=-2>TM</font></sup><i> Language Specification</i> or the equivalent chapter in the second edition.<p>
<a name="28518"></a>
Because of these potential problems, the Java virtual machine needs to verify for itself that the desired constraints are satisfied by the <code>class</code> files it attempts to incorporate. A Java virtual machine implementation verifies that each <code>class</code> file satisfies the necessary constraints at linking time <a href="Concepts.doc.html#22574">(&#167;2.17.3)</a>. Structural constraints on the Java virtual machine code may be checked using a simple theorem prover.<p>
<a name="9757"></a>
Linking-time verification enhances the performance of the interpreter. Expensive checks that would otherwise have to be performed to verify constraints at run time for each interpreted instruction can be eliminated. The Java virtual machine can assume that these checks have already been performed. For example, the Java virtual machine will already know the following:<p>
<ul><li>There are no operand stack overflows or underflows.      <p>
<li>All local variable uses and stores are valid.      <p>
<li>The arguments to all the Java virtual machine instructions are of valid types.
</ul><a name="66905"></a>
Sun's <code>class</code> file verifier is independent of any compiler. It should certify all code generated by Sun's compiler for the Java programming language; it should also certify code that other compilers can generate, as well as code that the current compiler could not possibly generate. Any <code>class</code> file that satisfies the structural criteria and static constraints will be certified by the verifier.<p>
<a name="66908"></a>
The <code>class</code> file verifier is also independent of the Java programming language. Programs written in other languages can be compiled into the <code>class</code> file format, but will pass verification only if all the same constraints are satisfied.<p>
<a name="9766"></a>
<h3>4.9.1    The Verification Process</h3>
<a name="10145"></a>
The <code>class</code> file verifier operates in four passes:
<p><a name="10146"></a>
<b> Pass 1:</b><br>
<a name="10147"></a>
When a prospective <code>class</code> file is loaded <a href="Concepts.doc.html#19175">(&#167;2.17.2)</a> by the Java virtual machine, the Java virtual machine first ensures that the file has the basic format of a <code>class</code> file. The first four bytes must contain the right magic number. All recognized attributes must be of the proper length. The <code>class</code> file must not be truncated or have extra bytes at the end. The constant pool must not contain any superficially unrecognizable information. <p>
<a name="23016"></a>
While <code>class</code> file verification properly occurs during class linking <a href="Concepts.doc.html#22574">(&#167;2.17.3)</a>, this check for basic <code>class</code> file integrity is necessary for any interpretation of the <code>class</code> file contents and can be considered to be logically part of the verification process.<p>
<a name="9770"></a>
<b> Pass 2:</b><br>
<a name="9771"></a>
When the <code>class</code> file is linked, the verifier performs all additional verification that can be done without looking at the <code>code</code> array of the <code>Code</code> attribute (<a href="ClassFile.doc.html#1546">&#167;4.7.3)</a>. The checks performed by this pass include the following:<p>
<ul><li>Ensuring that <code>final</code> classes are not subclassed and that <code>final</code> methods are not overridden.<p>
<li>Checking that every class (except <code>Object)</code> has a direct superclass.<p>
<li>Ensuring that the constant pool satisfies the documented static constraints: for example, that each <code>CONSTANT_Class_info</code> structure in the constant pool contains in its <code>name_index</code> item a valid constant pool index for a <code>CONSTANT_Utf8_info</code> structure. <p>
<li>Checking that all field references and method references in the constant pool have valid names, valid classes, and a valid type descriptor.
</ul><a name="9776"></a>
Note that when it looks at field and method references, this pass does not check to 
make sure that the given field or method actually exists in the given class, nor does it 
check that the type descriptors given refer to real classes. It checks only that these 
items are well formed. More detailed checking is delayed until passes 3 and 4.
<p><a name="9777"></a>
<b> Pass 3:</b><br>
<a name="9778"></a>
During linking, the verifier checks the <code>code</code> array of the <code>Code</code> attribute for each method of the <code>class</code> file by performing data-flow analysis on each method. The verifier ensures that at any given point in the program, no matter what code path is taken to reach that point, the following is true:<p>
<ul><li>The operand stack is always the same size and contains the same types of values.<p>
<li>No local variable is accessed unless it is known to contain a value of an appropriate type.<p>
<li>Methods are invoked with the appropriate arguments.<p>
<li>Fields are assigned only using values of appropriate types.<p>
<li>All opcodes have appropriate type arguments on the operand stack and in the local variable array.
</ul><a name="10178"></a>
For further information on this pass, see <a href="ClassFile.doc.html#9801">Section 4.9.2, "The Bytecode Verifier."</a>
<p><a name="10179"></a>
<strong>Pass 4: </strong><br>
For efficiency reasons, certain tests that could in principle be performed in 
Pass 3 are delayed until the first time the code for the method is actually invoked. In 
so doing, Pass 3 of the verifier avoids loading <code>class</code> files unless it has to. 
<p><a name="9790"></a>
For example, if a method invokes another method that returns an instance of class <code>A</code>, and that instance is assigned only to a field of the same type, the verifier does not bother to check if the class <code>A</code> actually exists. However, if it is assigned to a field of the type <code>B</code>, the definitions of both <code>A</code> and <code>B</code> must be loaded in to ensure that <code>A</code> is a subclass of <code>B</code>.<p>
<a name="9791"></a>
Pass 4 is a virtual pass whose checking is done by the appropriate Java virtual machine instructions. The first time an instruction that references a type is executed, the executing instruction does the following:<p>
<ul><li>Loads in the definition of the referenced type if it has not already been loaded.<p>
<li>Checks that the currently executing type is allowed to reference the type.
</ul><a name="9794"></a>
The first time an instruction invokes a method, or accesses or modifies a field, the executing instruction does the following:<p>
<ul><li>Ensures that the referenced method or field exists in the given class.<p>
<li>Checks that the referenced method or field has the indicated descriptor.<p>
<li>Checks that the currently executing method has access to the referenced method or field. 
</ul><a name="11934"></a>
The Java virtual machine does not have to check the type of the object on the operand stack. That check has already been done by Pass 3. Errors that are detected in Pass 4 cause instances of subclasses of <code>LinkageError</code> to be thrown.<p>
<a name="23175"></a>
A Java virtual machine implementation is allowed to perform any or all of the Pass 4 steps as part of Pass 3; see <a href="Concepts.doc.html#19042">2.17.1, "Virtual Machine Start-up"</a> for an example and more discussion.<p>
<a name="11935"></a>
In one of Sun's Java virtual machine implementations, after the verification has been performed, the instruction in the Java virtual machine code is replaced with an alternative form of the instruction. This alternative instruction indicates that the verification needed by this instruction has taken place and does not need to be performed again. Subsequent invocations of the method will thus be faster. It is illegal for these alternative instruction forms to appear in <code>class</code> files, and they should never be encountered by the verifier.<p>
<a name="9801"></a>
<h3>4.9.2    The Bytecode Verifier</h3>
<a name="9802"></a>
As indicated earlier, Pass 3 of the verification process is the most complex of the 
four passes of <code>class</code> file verification. This section looks at the verification of Java 
virtual machine code in Pass 3 in more detail.
<p><a name="9803"></a>
The code for each method is verified independently. First, the bytes that make up the code are broken up into a sequence of instructions, and the index into the <code>code</code> array of the start of each instruction is placed in an array. The verifier then goes through the code a second time and parses the instructions. During this pass a data structure is built to hold information about each Java virtual machine instruction in the method. The operands, if any, of each instruction are checked to make sure they are valid. For instance:<p>
<ul><li>Branches must be within the bounds of the <code>code</code> array for the method.<p>
<li>The targets of all control-flow instructions are each the start of an instruction. In the case of a <i>wide</i> instruction, the <i>wide</i> opcode is considered the start of the instruction, and the opcode giving the operation modified by that <i>wide</i> instruction is not considered to start an instruction. Branches into the middle of an instruction are disallowed. <p>
<li>No instruction can access or modify a local variable at an index greater than or equal to the number of local variables that its method indicates it allocates.<p>
<li>All references to the constant pool must be to an entry of the appropriate type. For example: the instruction <i>ldc</i> can be used only for data of type <code>int</code> or<code> float</code> or for instances of class <code>String</code>; the instruction <i>getfield</i> must reference a field.<p>
<li>The code does not end in the middle of an instruction. <p>
<li>Execution cannot fall off the end of the code.<p>
<li>For each exception handler, the starting and ending point of code protected by the handler must be at the beginning of an instruction or, in the case of the ending point, immediately past the end of the code. The starting point must be before the ending point. The exception handler code must start at a valid instruction, and it may not start at an opcode being modified by the <i>wide</i> instruction. 
</ul><a name="9809"></a>
For each instruction of the method, the verifier records the contents of the operand stack and the contents of the local variable array prior to the execution of that instruction. For the operand stack, it needs to know the stack height and the type of each value on it. For each local variable, it needs to know either the type of the contents of that local variable or that the local variable contains an unusable or unknown value (it might be uninitialized). The bytecode verifier does not need to distinguish between the integral types (e.g., <code>byte</code>, <code>short</code>, <code>char</code>) when determining the value types on the operand stack. <p>
<a name="9813"></a>
Next, a data-flow analyzer is initialized. For the first instruction of the method, the local variables that represent parameters initially contain values of the types indicated by the method's type descriptor; the operand stack is empty. All other local variables contain an illegal value. For the other instructions, which have not been examined yet, no information is available regarding the operand stack or local variables.<p>
<a name="9814"></a>
Finally, the data-flow analyzer is run. For each instruction, a "changed" bit indicates whether this instruction needs to be looked at. Initially, the "changed" bit is set only for the first instruction. The data-flow analyzer executes the following loop:<p>
<ol>
<a name="9815"></a>
<li>Select a virtual machine instruction whose "changed" bit is set. If no instruction remains whose "changed" bit is set, the method has successfully been verified. Otherwise, turn off the "changed" bit of the selected instruction.<p>
<a name="9816"></a>
<li>Model the effect of the instruction on the operand stack and local variable array by doing the following:<p>
<ul>
<li>If the instruction uses values from the operand stack, ensure that there are a sufficient number of values on the stack and that the top values on the stack are of an appropriate type. Otherwise, verification fails.<p>
<li>If the instruction uses a local variable, ensure that the specified local variable contains a value of the appropriate type. Otherwise, verification fails.<p>
<li>If the instruction pushes values onto the operand stack, ensure that there is sufficient room on the operand stack for the new values. Add the indicated types to the top of the modeled operand stack.<p>
<li>If the instruction modifies a local variable, record that the local variable now contains the new type.<p>
</ul><a name="9821"></a>
<li>Determine the instructions that can follow the current instruction. Successor instructions can be one of the following:<p>
<ul>
<li>The next instruction, if the current instruction is not an unconditional control transfer instruction (for instance <i>goto</i>, <i>return</i>, or  <i>athrow</i>). Verification fails if it is possible to "fall off" the last instruction of the method.<p>
<li>The target(s) of a conditional or unconditional branch or switch.<p>
<li>Any exception handlers for this instruction. <p>
</ul><a name="9825"></a>
<li>Merge the state of the operand stack and local variable array at the end of the execution of the current instruction into each of the successor instructions. In the special case of control transfer to an exception handler, the operand stack is set to contain a single object of the exception type indicated by the exception handler information.<p>
<ul>
<li>If this is the first time the successor instruction has been visited, record that the operand stack and local variable values calculated in steps 2 and 3 are the state of the operand stack and local variable array prior to executing the successor instruction. Set the "changed" bit for the successor instruction.<p>
<li>If the successor instruction has been seen before, merge the operand stack and local variable values calculated in steps 2 and 3 into the values already there. Set the "changed" bit if there is any modification to the values.<p>
</ul><a name="9828"></a>
<li>Continue at step 1.
</ol>
<a name="9829"></a>
To merge two operand stacks, the number of values on each stack must be identical. The types of values on the stacks must also be identical, except that differently typed <code>reference</code> values may appear at corresponding places on the two stacks. In this case, the merged operand stack contains a <code>reference</code> to an instance of the first common superclass of the two types. Such a reference type always exists because the type <code>Object</code> is a superclass of all class and interface types. If the operand stacks cannot be merged, verification of the method fails.<p>
<a name="9830"></a>
To merge two local variable array states, corresponding pairs of local variables are compared. If the two types are not identical, then unless both contain <code>reference</code> values, the verifier records that the local variable contains an unusable value. If both of the pair of local variables contain <code>reference</code> values, the merged state contains a <code>reference</code> to an instance of the first common superclass of the two types.<p>
<a name="9831"></a>
If the data-flow analyzer runs on a method without reporting a verification failure, then the method has been successfully verified by Pass 3 of the <code>class</code> file verifier.<p>
<a name="9832"></a>
Certain instructions and data types complicate the data-flow analyzer. We now examine each of these in more detail.<p>
<a name="9833"></a>
<h3>4.9.3    Values of Types <code>long</code> and <code>double</code></h3>
<a name="9834"></a>
Values of the <code>long</code> and <code>double</code> types are treated specially by the verification process.

<p><a name="63126"></a>
Whenever a value of type <code>long</code> or <code>double</code> is moved into a local variable at index <code>n</code>, index <code>n</code> &#32;+ &#32;<code>1</code> is specially marked to indicate that it has been reserved by the value at index <code>n</code> and may not be used as a local variable index. Any value previously at index <code>n</code> &#32;+ &#32;<code>1</code> becomes unusable.<p>
<a name="9836"></a>
Whenever a value is moved to a local variable at index <code>n</code>, the index <code>n</code> &#32;- &#32;<code>1</code> is examined to see if it is the index of a value of type <code>long</code> or <code>double</code>. If so, the local variable at index <code>n</code> &#32;- &#32;<code>1</code> is changed to indicate that it now contains an unusable value. Since the local variable at index <code>n</code> has been overwritten, the local variable at index <code>n</code> &#32;- &#32;<code>1</code> cannot represent a value of type <code>long</code> or <code>double</code>.<p>
<a name="9837"></a>
Dealing with values of types <code>long</code> or <code>double</code> on the operand stack is simpler; the verifier treats them as single values on the stack. For example, the verification code for the <i>dadd</i> opcode (add two <code>double</code> values) checks that the top two items on the stack are both of type <code>double</code>. When calculating operand stack length, values of type <code>long</code> and <code>double</code> have length two.<p>
<a name="9838"></a>
Untyped instructions that manipulate the operand stack must treat values of type <code>double</code> and <code>long</code> as atomic (indivisible). For example, the verifier reports a failure if the top value on the stack is a <code>double</code> and it encounters an instruction such as <i>pop</i> or <i>dup</i>. The instructions <i>pop2</i> or <i>dup2</i> must be used instead.<p>
<a name="9839"></a>
<h3>4.9.4    Instance Initialization Methods and Newly Created Objects</h3>
<a name="9840"></a>
Creating a new class instance is a multistep process. The statement
<p><pre><br><a name="9841"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>...
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>new myClass(i, j, k);
</code><a name="10517"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>...
</code><br></pre><a name="10420"></a>
can be implemented by the following:
<p><pre><br><a name="15996"></a>&nbsp;&nbsp;&nbsp;&nbsp;...
&nbsp;&nbsp;&nbsp;&nbsp;new	#1			// Allocate uninitialized space for <code>myClass
</code>&nbsp;&nbsp;&nbsp;&nbsp;dup				// Duplicate object on the operand stack
&nbsp;&nbsp;&nbsp;&nbsp;iload_1			// Push i
&nbsp;&nbsp;&nbsp;&nbsp;iload_2			// Push j
&nbsp;&nbsp;&nbsp;&nbsp;iload_3			// Push k
&nbsp;&nbsp;&nbsp;&nbsp;invokespecial #5 		// Invoke <code>myClass.&lt;init&gt;</code> 
<a name="10515"></a>&nbsp;&nbsp;&nbsp;&nbsp;...
<br></pre><a name="41910"></a>
This instruction sequence leaves the newly created and initialized object on top of 
the operand stack. (Additional examples of compilation to the instruction set of the 
Java virtual machine are given in <a href="Compiling.doc.html#2839">Chapter 7</a>, <a href="Compiling.doc.html#2989">"Compiling for the Java Virtual 
Machine."</a>)
<p><a name="9847"></a>
The instance initialization method <a href="Overview.doc.html#12174">(&#167;3.9)</a> for class <code>myClass</code> sees the new uninitialized object as its <code>this</code> argument in local variable <code>0</code>. Before that method invokes another instance initialization method of <code>myClass</code> or its direct superclass on <code>this</code>, the only operation the method can perform on <code>this</code> is assigning fields declared within <code>myClass</code>.<p>
<a name="9848"></a>
When doing dataflow analysis on instance methods, the verifier initializes local variable <code>0</code> to contain an object of the current class, or, for instance initialization methods, local variable <code>0</code> contains a special type indicating an uninitialized object. After an appropriate instance initialization method is invoked (from the current class or the current superclass) on this object, all occurrences of this special type on the verifier's model of the operand stack and in the local variable array are replaced by the current class type. The verifier rejects code that uses the new object before it has been initialized or that initializes the object more than once. In addition, it ensures that every normal return of the method has invoked an instance initialization method either in the class of this method or in the direct superclass.<p>
<a name="9849"></a>
Similarly, a special type is created and pushed on the verifier's model of the operand stack as the result of the Java virtual machine instruction <i>new</i>. The special type indicates the instruction by which the class instance was created and the type of the uninitialized class instance created. When an instance initialization method is invoked on that class instance, all occurrences of the special type are replaced by the intended type of the class instance. This change in type may propagate to subsequent instructions as the dataflow analysis proceeds.<p>
<a name="22736"></a>
The instruction number needs to be stored as part of the special type, as there may be multiple not-yet-initialized instances of a class in existence on the operand stack at one time. For example, the Java virtual machine instruction sequence that implements <p>
<a name="22737"></a>
<blockquote><code>new InputStream(new 						Foo(), new &#32;InputStream("foo"))</code></blockquote><p>
<a name="22738"></a>
may have two uninitialized instances of <code>InputStream</code> on the operand stack at once. 
When an instance initialization method is invoked on a class instance, only those 
occurrences of the special type on the operand stack or in the local variable array 
that are the <em>same object</em> as the class instance are replaced.
<p><a name="22722"></a>
A valid instruction sequence must not have an uninitialized object on the operand stack or in a local variable during a backwards branch, or in a local variable in code protected by an exception handler or a <code>finally</code> clause. Otherwise, a devious piece of code might fool the verifier into thinking it had initialized a class instance when it had, in fact, initialized a class instance created in a previous pass through a loop.<p>
<a name="9855"></a>
<h3>4.9.5    Exception Handlers</h3>
<a name="9856"></a>
Java virtual machine code produced by Sun's compiler for the Java programming 
language always generates exception handlers such that: 
<p><ul><li>Either the ranges of instructions protected by two different exception handlers always are completely disjoint, or else one is a subrange of the other. There is never a partial overlap of ranges.<p>
<li>The handler for an exception will never be inside the code that is being protected.<p>
<li>The only entry to an exception handler is through an exception. It is impossible to fall through or "goto" the exception handler.
</ul><a name="9860"></a>
These restrictions are not enforced by the <code>class</code> file verifier since they do not pose a 
threat to the integrity of the Java virtual machine. As long as every nonexceptional 
path to the exception handler causes there to be a single object on the operand stack, 
and as long as all other criteria of the verifier are met, the verifier will pass the code.
<p><a name="9862"></a>
<h3>4.9.6    Exceptions and <code>finally</code></h3>
<a name="9863"></a>
Given the code fragment
<p><pre><br><a name="10497"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>...
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>try {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>    startFaucet();
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>    waterLawn();
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>} finally {
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>    stopFaucet();
</code>&nbsp;&nbsp;&nbsp;&nbsp;<code>}
</code><a name="10513"></a>&nbsp;&nbsp;&nbsp;&nbsp;<code>...
</code><br></pre><a name="14583"></a>
the Java programming language guarantees that <code>stopFaucet</code> is invoked (the faucet
is turned off) whether we finish watering the lawn or whether an exception 
occurs while starting the faucet or watering the lawn. That is, the <code>finally</code> clause 
is guaranteed to be executed whether its <code>try</code> clause completes normally or completes
abruptly by throwing an exception.
<p><a name="9867"></a>
To implement the <code>try-finally</code> construct, Sun's compiler for the Java programming language uses the exception-handling facilities together with two special instructions: <i>jsr</i> ("jump to subroutine") and <i>ret</i> ("return from subroutine"). The <code>finally</code> clause is compiled as a subroutine within the Java virtual machine code for its method, much like the code for an exception handler. When a <i>jsr</i> instruction that invokes the subroutine is executed, it pushes its return address, the address of the instruction after the <i>jsr</i> that is being executed, onto the operand stack as a value of type <code>returnAddress</code>. The code for the subroutine stores the return address in a local variable. At the end of the subroutine, a <i>ret</i> instruction fetches the return address from the local variable and transfers control to the instruction at the return address.<p>
<a name="15008"></a>
Control can be transferred to the <code>finally</code> clause (the <code>finally</code> subroutine can be invoked) in several different ways. If the <code>try</code> clause completes normally, the <code>finally</code> subroutine is invoked via a <i>jsr</i> instruction before evaluating the next expression. A <code>break</code> or <code>continue</code> inside the <code>try</code> clause that transfers control outside the <code>try</code> clause executes a <i>jsr</i> to the code for the <code>finally</code> clause first. If the <code>try</code> clause executes a <code>return</code>, the compiled code does the following:<p>
<ol>
<a name="15009"></a>
<li>Saves the return value (if any) in a local variable.
<a name="15010"></a>
<li>Executes a <i>jsr</i> to the code for the <code>finally</code> clause.
<a name="15011"></a>
<li>Upon return from the <code>finally</code> clause, returns the value saved in the local variable.
</ol>
<a name="17627"></a>
The compiler sets up a special exception handler, which catches any exception thrown by the <code>try</code> clause. If an exception is thrown in the <code>try</code> clause, this exception handler does the following:<p>
<ol>
<a name="9869"></a>
<li>Saves the exception in a local variable.
<a name="9870"></a>
<li>Executes a <i>jsr</i> to the <code>finally</code> clause.
<a name="14674"></a>
<li>Upon return from the <code>finally</code> clause, rethrows the exception.
</ol>
<a name="14679"></a>
For more information about the implementation of the <code>try-finally</code> construct, see 
<a href="Compiling.doc.html#13789">Section 7.13, "Compiling <code>finally</code>."</a>
<p><a name="9877"></a>
The code for the <code>finally</code> clause presents a special problem to the verifier. Usually, if a particular instruction can be reached via multiple paths and a particular local variable contains incompatible values through those multiple paths, then the local variable becomes unusable. However, a <code>finally</code> clause might be called from several different places, yielding several different circumstances:<p>
<ul><li>The invocation from the exception handler may have a certain local variable that contains an exception. <p>
<li>The invocation to implement <code>return</code> may have some local variable that contains the return value. <p>
<li>The invocation from the bottom of the <code>try</code> clause may have an indeterminate value in that same local variable. 
</ul><a name="9881"></a>
The code for the <code>finally</code> clause itself might pass verification, but after completing the updating all the successors of the <i>ret</i> instruction, the verifier would note that the local variable that the exception handler expects to hold an exception, or that the return code expects to hold a return value, now contains an indeterminate value.<p>
<a name="9882"></a>
Verifying code that contains a <code>finally</code> clause is complicated. The basic idea is the following:<p>
<ul><li>Each instruction keeps track of the list of <i>jsr</i> targets needed to reach that instruction. For most code, this list is empty. For instructions inside code for the <code>finally</code> clause, it is of length one. For multiply nested <code>finally</code> code (extremely rare!), it may be longer than one.<p>
<li>For each instruction and each <i>jsr</i> needed to reach that instruction, a bit vector is maintained of all local variables accessed or modified since the execution of the <i>jsr</i> instruction.<p>
<li>When executing the <i>ret</i> instruction, which implements a return from a subroutine, there must be only one possible subroutine from which the instruction can be returning. Two different subroutines cannot "merge" their execution to a single <i>ret</i> instruction.<p>
<li>To perform the data-flow analysis on a <i>ret</i> instruction, a special procedure is used. Since the verifier knows the subroutine from which the instruction must be returning, it can find all the <i>jsr</i> instructions that call the subroutine and merge the state of the operand stack and local variable array at the time  of the <i>ret</i> instruction into the operand stack and local variable array of the instructions following the <i>jsr</i>. Merging uses a special set of values for local variables:<p>
<ul>
<li>For any local variable that the bit vector (constructed above) indicates has been accessed or modified by the subroutine, use the type of the local variable at the time of the <i>ret</i>.<p>
<li>For other local variables, use the type of the local variable before the <i>jsr</i> instruction.  
</ul>
</ul><a name="88659"></a>
<hr><h2>4.10    Limitations of the Java Virtual Machine</h2>
<a name="6254"></a>
The following limitations of the Java virtual machine are implicit in the <code>class</code> file 
format:
<p><ul><li>The per-class or per-interface constant pool is limited to 65535 entries by the 16-bit <code>constant_pool_count</code> field of the <code>ClassFile</code> structure <a href="ClassFile.doc.html#74353">(&#167;4.1)</a>. This acts as an internal limit on the total complexity of a single class or interface.<p>
<li>The amount of code per non-<code>native</code>, non-<code>abstract</code> method is limited to 65536 bytes by the sizes of the indices in the <code>exception_table</code> of the <code>Code</code> attribute (<a href="ClassFile.doc.html#1546">&#167;4.7.3)</a>, in the <code>LineNumberTable</code> attribute <a href="ClassFile.doc.html#22856">(&#167;4.7.8)</a>, and in the <code>LocalVariableTable</code> attribute <a href="ClassFile.doc.html#5956">(&#167;4.7.9)</a>. <p>
<li>The greatest number of local variables in the local variables array of a frame created upon invocation of a method is limited to 65535 by the size of the <code>max_locals</code> item of the <code>Code</code> attribute <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a> giving the code of the method. Note that values of type <code>long</code> and <code>double</code> are each considered to reserve two local variables and contribute two units toward the <code>max_locals</code> value, so use of local variables of those types further reduces this limit.<p>
<li>The number of fields that may be declared by a class or interface is limited to 65535 by the size of the <code>fields_count</code> item of the <code>ClassFile</code> structure <a href="ClassFile.doc.html#74353">(&#167;4.1)</a>. Note that the value of the <code>fields_count</code> item of the <code>ClassFile</code> structure does not include fields that are inherited from superclasses or superinterfaces.<p>
<li>The number of methods that may be declared by a class or interface is limited to 65535 by the size of the <code>methods_count</code> item of the <code>ClassFile</code> structure <a href="ClassFile.doc.html#74353">(&#167;4.1)</a>. Note that the value of the <code>methods_count</code> item of the <code>ClassFile</code> structure does not include methods that are inherited from superclasses or superinterfaces. <p>
<li>The number of direct superinterfaces of a class or interface is limited to 65535 by the size of the <code>interfaces_count</code> item of the <code>ClassFile</code> structure <a href="ClassFile.doc.html#74353">(&#167;4.1)</a>.<p>
<li>The size of an operand stack in a frame <a href="Overview.doc.html#17257">(&#167;3.6)</a> is limited to 65535 values by the <code>max_stack</code> field of the <code>Code_attribute</code> structure <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a>. Note that values of type <code>long</code> and <code>double</code> are each considered to contribute two units toward the <code>max_stack</code> value, so use of values of these types on the operand stack  further reduces this limit.<p>
<li>The number of local variables in a frame <a href="Overview.doc.html#17257">(&#167;3.6)</a> is limited to 65535 by the <code>max_locals</code> field of the <code>Code_attribute</code> structure <a href="ClassFile.doc.html#1546">(&#167;4.7.3)</a> and the 16-bit local variable indexing of the Java virtual machine instruction set.<p>
<li>The number of dimensions in an array is limited to 255 by the size of the <i>dimensions</i> opcode of the <i>multianewarray</i> instruction and by the constraints imposed on the <i>multianewarray</i>, <i>anewarray</i>, and <i>newarray</i> instructions by <a href="ClassFile.doc.html#9308">&#167;4.8.2</a>.<p>
<li>The number of method parameters is limited to 255 by the definition of a method descriptor <a href="ClassFile.doc.html#7035">(&#167;4.3.3)</a>, where the limit includes one unit for <code>this</code> in the case of instance or interface method invocations. Note that a method descriptor is defined in terms of a notion of method parameter length in which a parameter of type <code>long</code> or <code>double</code> contributes two units to the length, so parameters of these types further reduce the limit.<p>
<li>The length of field and method names, field and method descriptors, and other constant string values is limited to 65535 characters by the 16-bit unsigned <code>length</code> item of the <code>CONSTANT_Utf8_info</code> structure <a href="ClassFile.doc.html#7963">(&#167;4.4.7)</a>. Note that the limit is on the number of bytes in the encoding and not on the number of encoded characters. UTF-8 encodes some characters using two or three bytes. Thus, strings incorporating multibyte characters are further constrained.
</ul>

<hr>
<sup>1</sup><a name="75883"></a>
 The Java virtual machine implementation of Sun's JDK release 1.0.2 supports <code>class</code> file format versions 45.0 through 45.3 inclusive. Sun's JDK releases 1.1.X can support <code>class</code> file formats of versions in the range 45.0 through 45.65535 inclusive. Implementations of version 1.2 of the Java 2 platform can support <code>class</code> file formats of versions in the range 45.0 through 46.0 inclusive.<p>
<sup>2</sup><a name="16628"></a>
 In retrospect, making 8-byte constants take two constant pool entries was a poor choice.<p>
<sup>3</sup><a name="41454"></a>
 		The first edition of <i>The Java</i><sup><font size=-2>TM</font></sup><i> Language Specification</i> required that "<code>com</code>" be in uppercase in this example. The second edition will reverse that convention and use lowercase.<p>
<sup>4</sup><a name="17078"></a>
 The fact that <code>end_pc</code> is exclusive is a historical mistake in the design of the Java virtual machine: if the Java virtual machine code for a method is exactly 65535 bytes long and ends with an instruction that is 1 byte long, then that instruction cannot be protected by an exception handler. A compiler writer can work around this bug by limiting the maximum size of the generated Java virtual machine code for any method, instance initialization method, or static initializer (the size of any <code>code</code> array) to 65534 bytes.<p>
<sup>5</sup><a name="79999"></a>
 The <code>InnerClasses</code> attribute was introduced in JDK release 1.1 to support nested classes and interfaces.<p>
<sup>6</sup><a name="88570"></a>
 The <code>Synthetic</code> attribute was introduced in JDK release 1.1 to support nested classes and interfaces.<p>
<sup>7</sup><a name="78236"></a>
 The <code>Deprecated</code> attribute was introduced in JDK release 1.1 to support the <code>@deprecated</code> tag in documentation comments.<p>
<!-- This inserts footnotes--><p>
<a href="VMSpecTOC.doc.html">Contents</a> | <a href="Overview.doc.html">Prev</a> | <a href="ConstantPool.doc.html">Next</a> | <a href="VMSpecIX.fm.html">Index</a>
<p>
<font size="-1"><i>The Java</i><sup><font size=-2>TM</font></sup><i> Virtual Machine Specification </i><br>
<!-- HTML generated by Suzette Pelouch on March 30, 1999 -->
<i><a href="Copyright.doc.html">Copyright &#169 1999 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:jvm@java.sun.com">jvm@java.sun.com</a>
</font>
</body></html>
